Skill set: When nginx acts as a proxy, check which server the request is forwarded to

When using Nginx to proxy multiple servers to perform load, how to check which server a request is forwarded to?

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

Add the following red configuration:

copy code
    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;
        }
    }
copy code

Restart Nginx, re-visit, check the header information of the request with F12 in the browser, and you can see the IP of the current server

 

 

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

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326526883&siteId=291194637