技巧集:nginx作代理时,查看请求被转发到哪台服务器

使用Nginx代理多台服务器实行负载的时候,如何查看某一个请求被转发到哪台服务器上呢?

upstream demo { 
     server 127.0.0.1:8781;
server 127.0.0.1:8087;
}

加上如下红色配置:

复制代码
    server {
        listen       80;
        server_name  demo.testcas.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            #index  index.html index.htm;
	  add_header backendIP $upstream_addr;
       add_header backendCode $upstream_status;
	   proxy_pass http://demo;
        }
    }
复制代码

重启Nginx,重新访问,在浏览器中F12查看request的Headers信息,可以看到当前服务器的IP

 

 

https://www.cnblogs.com/notDog/p/5336900.html

https://www.zhihu.com/question/21464666

猜你喜欢

转载自m635674608.iteye.com/blog/2400573