标签:host set request php wro 问题 location 负载 serve
nginx负载均衡配置,主要是proxy_pass,upstream的使用。
注意问题,多台机器间session的共享问题。
不用session,用户cookie。或者用redis替代session。
三台服务器,一台nginx转发(10.0.0.1),两台服务器(10.0.0.2,10.0.0.3)。
nginx转发配置,
upstream balance.xxx.com
{
server 10.0.0.2:80;
server 10.0.0.3:80;
}
server
{
listen 80;
server_name balance.xxx.com;
location /
{
proxy_pass http://balance.xxx.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
access_log /home/wwwlogs/access.log;
}
服务器1
server
{
listen 80;
#listen [::]:80 default_server ipv6only=on;
server_name balance.xxx.com;
index index.html index.htm index.php admin.php;
root /home/wwwroot/default/load;
#error_page 404 /404.html;
include enable-php-pathinfo.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
}
access_log /home/wwwlogs/access.log;
}
服务器2
server
{
listen 80;
#listen [::]:80 default_server ipv6only=on;
server_name balance.xxx.com;
index index.html index.htm index.php admin.php;
root /home/wwwroot/default/load;
#error_page 404 /404.html;
include enable-php-pathinfo.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
}
}
access_log /home/wwwlogs/access.log;
}
配好之后,记得重启nginx。
标签:host set request php wro 问题 location 负载 serve
原文地址:https://www.cnblogs.com/jiqing9006/p/10676085.html