nginx 反向代理获取超时响应

nginx 反向代理获取超时响应

我得到了连接已超时在配置某个内部服务器的反向代理后。

知道如果我运行 wget,我会得到 200 OK 响应并且正确的页面被下载。

[root@web1 nginx]# wget http://www.example.com:81
--2016-04-08 16:00:16--  http://www.example.com:81/
Resolving www.example.com (www.example.com)... ip-address
Connecting to www.example.com (www.example.com)|ip-address|:81... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1785 (1.7K) [text/html]
Saving to: قindex.htmlق

100%[=====================================================================================================================================================================>] 1,785       --.-K/s   in 0s

2016-04-08 16:00:16 (57.3 MB/s) - قindex.htmlق saved [1785/1785]

nginx.conf

http {
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

    server {
        server_name localhost;
        disable_symlinks if_not_owner;
        listen 80;
        include /etc/nginx/vhosts-includes/*.conf;
        location @fallback {
            error_log /dev/null crit;
            proxy_pass http://127.0.0.1:8080;
            proxy_redirect http://127.0.0.1:8080 /;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            access_log off ;
        }
    }
    include /etc/nginx/vhosts/*/*;
}

在 /etc/nginx/vhost/*/exmaple.conf 下

我已经尝试过这两种配置:

server {
     server_name www.example.com;

     charset off;
     disable_symlinks if_not_owner from=$root_path;
     index index.php index.html;
     root $root_path;
     set $root_path /var/www/uexample/data/www/example.net;
     access_log /var/www/httpd-logs/example.com.access.log ;
     error_log /var/www/httpd-logs/example.com.error.log notice;
     include /etc/nginx/vhosts-includes/*.conf;


    location / {
        proxy_pass http://localhost:5601/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    ssi on;
    listen 81;
}


server {
    server_name www.example.com;
    location / {
        proxy_pass http://localhost:5601/;
    }
    listen 81;
}

答案1

由于无法使用 80 以外的端口(原因未知),解决方法是使用子域并监听 ip 地址:端口。

server {
    server_name subdomain.domain.com;
    listen IP-Address:80;

    location / {
        proxy_pass http://localhost:5601/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
    ssi on;
}

相关内容