使用Nginx做反向代理時,如何查看web請求被落地到哪台服務器


使用Nginx反向代理多台服務器實行負載均衡的時候,如何查看某一個請求被轉發到哪台服務器上呢?

在nginx.conf添加配置:

 

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; #要與upstream 標紅的demo保持一致 } }

重啟Nginx,重新訪問,在瀏覽器中F12查看request的Headers信息,可以看到當前服務器的IP


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM