nginx.conf
配置文件
上游 test.com {
# ip_hash;
服务器127.0.0.1:80 权重=10;
#服务器192.168.1.116:80权重=1;
#服务器116.62.19.122:80权重=1;
}
服务器 {
听80;
服务器名称 test.com;
根/var/网站/测试;
索引index.phpindex.htmlindex.htm;
字符集utf-8;
地点 / {
proxy_pass http://test.com;
proxy_set_header 主机 $host;
proxy_set_header X-真实IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering 关闭;
try_files $uri $uri/ /index.php?$query_string;
自动索引开启;
}
位置 ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:8000;
fastcgi_split_path_info ^(.+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
包括 fastcgi_params;
}
}
hosts
文件
结果如下:
这是什么情况??求大神解决...
为情所困2017-05-16 13:10:15
你把后端服务端口和反向代理的监听端口区分开不要用同一个端口,不就可以了么
或者用server_name去区分走哪个server也行啊
比如 test.com 请求到192.168.1.100的80端口 使用的是域名test.com访问,你写一个server用server_name test.com来接受请求,代理的时候用test1.com 然后在开一个server用server_name test1.com这样子真实请求和代理请求由两个server去处理不就分开了么