小奋斗 - 轻松学习从此开始!
IT小奋斗群 QQ群:62017228

Nginx反向代理无法访问的解决方案

故障现象:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

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

配置如下:

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;

        }

}

小奋斗文章

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

我来评几句
登录后评论

已发表评论数(0)