为了方便调试或者查找问题,让nginx负载均衡返回后端处理机器的实际
首先按照教程重新编译最新的nginx,添加第三方的模块headers-more-nginx-module
https://my.oschina.net/liuguangqiang/blog/2243648
安装完成后在nginx配置文件里重写相应的header
upstream demoServer
{
server 127.0.0.1:8080;
server 127.0.0.1:8081;
server 127.0.0.1:8082;
}
server {
listen 80;
server_name xxxx.com;
location / {
proxy_pass http://demoServer ;
include proxy.conf;
more_set_headers "Server: Demo Web Server";
more_set_headers "back-server: $upstream_addr";
}
location ^~/static/ {
root /data/web-server/;
more_set_headers "Server: Demo Web Static Server";
more_set_headers "back-server: static-server";
expires 1h;
}
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
}
实际效果如下图