2321321 发表于 2017-1-5 15:41:26

nginx+php-fpm动静分离

关键配置

1、nginx.conf:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
upstream phpCluster{
    server web-php1.life.com:9000;
    server web-php2.life.com:9000;
}
server {
    listen       8080;
    server_namenginx.life.com;
    index index.php index.html index.htm;
    root/home/nginx/html;
    charsetutf-8;
    location ~ .*\.(php|php5) {      
      fastcgi_passphpCluster;
      fastcgi_index index.php;
      include fastcgi.conf;
      set $path_info "";
      set $real_script_name $fastcgi_script_name;
      if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
         set $real_script_name $1;
         set $path_info $2;
      }
      
      fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
      fastcgi_param SCRIPT_NAME $real_script_name;
      fastcgi_param PATH_INFO $path_info;
    }
}




2、php-fpm.conf

1
2
3
listen = 0.0.0.0:9000
listen.allowed_clients = 10.0.2.11,10.0.2.12,127.0.0.1
request_terminate_timeout = 60s




3、网站根目录
nginx服务器与php服务器的根目录要一致,并且需要赋予相应的权限

nginx:root/home/nginx/html;
php:

1
2
3
4
5
6
$ ll
total 12
drwxrwxr-x 2 php php 4096 Dec 30 16:04 crontab
drwxrwxr-x 3 php php 4096 Dec 30 16:04 data
lrwxrwxrwx 1 php php   17 Dec 30 16:07 html -> /home/nginx/html/
drwxr-xr-x 9 php php 4096 Dec 30 16:01 php






页: [1]
查看完整版本: nginx+php-fpm动静分离