Nginx 反向代理导致 504 网关超时 [英] Nginx reverse proxy causing 504 Gateway Timeout

查看:100
本文介绍了Nginx 反向代理导致 504 网关超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Nginx 作为接收请求的反向代理,然后执行 proxy_pass 从运行在端口 8001 上的上游服务器获取实际的 Web 应用程序.

I am using Nginx as a reverse proxy that takes requests then does a proxy_pass to get the actual web application from the upstream server running on port 8001.

如果我转到 mywebsite.com 或执行 wget,我会在 60 秒后收到 504 网关超时...但是,如果我加载 mywebsite.com:8001,应用程序将按预期加载!

If I go to mywebsite.com or do a wget, I get a 504 Gateway Timeout after 60 seconds... However, if I load mywebsite.com:8001, the application loads as expected!

所以有些东西阻止了 Nginx 与上游服务器的通信.

So something is preventing Nginx from communicating with the upstream server.

所有这一切都是在我的托管公司重置运行我的东西的机器之后开始的,在此之前没有任何问题.

All this started after my hosting company reset the machine my stuff was running on, prior to that no issues whatsoever.

这是我的虚拟主机服务器块:

server {
    listen   80;
    server_name mywebsite.com;

    root /home/user/public_html/mywebsite.com/public;

    access_log /home/user/public_html/mywebsite.com/log/access.log upstreamlog;
    error_log /home/user/public_html/mywebsite.com/log/error.log;

    location / {
        proxy_pass http://xxx.xxx.xxx.xxx:8001;
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
} 

以及我的 Nginx 错误日志的输出:

2014/06/27 13:10:58 [error] 31406#0: *1 upstream timed out (110: Connection timed out) while connecting to upstream, client: xxx.xx.xxx.xxx, server: mywebsite.com, request: "GET / HTTP/1.1", upstream: "http://xxx.xxx.xxx.xxx:8001/", host: "mywebsite.com"

推荐答案

大概可以多加几行来增加上游的超时时间.以下示例将超时设置为 300 秒:

Probably can add a few more line to increase the timeout period to upstream. The examples below sets the timeout to 300 seconds :

proxy_connect_timeout       300;
proxy_send_timeout          300;
proxy_read_timeout          300;
send_timeout                300;

这篇关于Nginx 反向代理导致 504 网关超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆