首页 > 解决方案 > Nginx 无法代理端口

问题描述

我使用 Nginx 作为负载均衡器。它能够将请求路由到指定的主机地址,但不能路由到上游块中提到的端口。它总是将它发送到默认端口。

我尝试了多种方法来修改proxy_set_header Host, proxy_set_header X-Forwarded-For, proxy_set_header X-Real-IP,proxy_set_header X-Forwarded-Protoproxy_set_header Referer。但似乎没有任何效果。

我在 Azure 中安装了 Nginx 服务器,并尝试访问同一虚拟网络中的 VM。

预期行为: http://localhost/sites -----> http://zzz:9081/sites(应考虑 IP:Port) 实际行为: http://localhost/sites -----> http://zzz/sites(需要IP,但端口是80/默认监听端口)。

  upstream alb {
      ip_hash;
      server zzz:9081;
      server zzz:9080;
    }


     server {
            listen       80;
            server_name  localhost;
            # root         /usr/share/nginx/html;


            location /sites {
               proxy_pass http://alb/sites;
               proxy_set_header X-Real-IP $remote_addr;
               }
}

任何帮助将不胜感激。

标签: azurenginxopenamnginx-reverse-proxy

解决方案


推荐阅读