proxy_pass 模式
upstream httpserver {
ip_hash;
server 172.20.39.79 weight=1;
server 172.20.39.80 weight=1;
server 172.20.39.81 weight=1;
}
server
{
listen 80;
server_name xxx.abc.com *.xxx.abc.com;
index index.html index.htm index.php default.html default.htm default.php;
root /data/www/xxx/Public;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://httpserver;
}
#access_log /data/wwwlogs/xxx.abc.com.log;
}
fastcgi_pass 模式
注意:该模式必须保证在nginx服务器上有php服务器上对应的被请求php文件(只要能找到对应文件名即可,不需要php文件内容相同,空文件即可),主要是因为nginx会检查文件是否存在,单入口模式的系统,只要有index.php就可以了
nginx 配置,服务器IP 172.20.39.78
upstream phpserver {
ip_hash;
server 172.20.39.79:9000 weight=1;
server 172.20.39.80:9000 weight=1;
server 172.20.39.81:9000 weight=1;
}
server
{
listen 80;
server_name xxx.abc.com *.xxx.abc.com;
index index.html index.htm index.php default.html default.htm default.php;
root /data/www/xxx/Public;
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ /uploads/.*\.php$ { deny all; }
location ~ [^/]\.php(/|$)
{
fastcgi_pass phpserver;
fastcgi_index index.php;
include fastcgi.conf;
include fastcgi_params;
fastcgi_param PHP_ADMIN_VALUE "open_basedir=/data/www/xxx/:/tmp/:/proc/";
include pathinfo.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /data/wwwlogs/xxx.abc.com.log;
}
php-fpm.conf 配置 服务器IP 172.20.39.80,其他两台服务器类似
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice
[www]
listen = 9000
listen.backlog = -1
listen.allowed_clients = 127.0.0.1,172.20.39.80,172.20.39.78
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 120
pm.start_servers = 30
pm.min_spare_servers = 30
pm.max_spare_servers = 90
pm.max_requests = 1024
pm.process_idle_timeout = 10s
request_terminate_timeout = 60
request_slowlog_timeout = 0
slowlog = /data/logs/php_slow.log
listen = 127.0.0.1:9000,172.20.39.80:9000 # fpm 监听端口(本机网卡IP),多个IP逗号分隔。可用格式为: ‘ip:port’, ‘port’, ‘/path/to/unix/socket’
listen.allowed_clients = 127.0.0.1,172.20.39.80,172.20.39.78 # 允许访问 FastCGI 进程的 IP(本机IP或其他主机IP),多个IP逗号分隔。如果需要其他主机也能访问,除这里需要写入其他主机IP外,上面的 listen 配置里面也必须有本机网卡IP,不能只有127.0.0.1的回环网卡地址,因为其他主机是无法访问本机的回环地址的。