故障现象:

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


