NGINX反向代理非80端口无法访问

实用教程 admin 1年前 (2023-03-17) 645次浏览 0个评论

故障现象:

1、被代理机器单独访问正常;

2、通过集群访问,连接不带端口,无法访问(502);

配置如下:

upstream test {
    ip_hash;
    server   10.86.87.85:8080;
    server   10.86.87.195:8080;
}

server {
        listen 8000;    
        server_name 10.86.87.101;

        location / {
            proxy_pass http://test;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host    $host;
            real_ip_header X-Real-IP;
        }
}

原因:

反向代理端口为非80端口时,需要配置上代理端口。

完整配置如下:

upstream test {
    ip_hash;
    server   10.86.87.85:8080;
    server   10.86.87.195:8080;
    check interval=1000 rise=2 fall=5 timeout=1000 type=http;
    check_http_send "GET /index.jsp  HTTP/1.0\r\n\r\n";
    check_http_expect_alive http_2xx http_3xx;
}

server {
        listen 8000; 
        server_name 10.86.87.101;
        index index.jsp index.html index.htm;
        client_max_body_size 100m;
        access_log  logs/test_access.log  logstash_json;

        location / {
            proxy_pass http://test;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host    $host:8000;  # 加上被代理的端口号,这里是关键
            real_ip_header X-Real-IP;
        }
}

原文:

https://www.jianshu.com/p/a9bc8ffe65ab


VPS小白 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:NGINX反向代理非80端口无法访问
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址