【问题标题】:nginx responses 504/502 gateway timeout error at timesnginx有时会响应504/502网关超时错误
【发布时间】:2019-09-01 00:56:08
【问题描述】:

我遇到了一个问题。

我有 6 个快速应用程序在 Node 上运行,并使用 Nginx 作为反向代理,它们都运行了几个月没有问题。但最近,当我尝试导航到任何网站的内页时,它返回了 502 或 504 nginx 错误。

当我尝试在 ngrok 或本地运行应用程序时,它们可以正常运行,但在生产服务器上却出现 504/502 错误。

Nginx 日志说 2019/04/10 16:38:12 [error] 1362#1362: *245 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 37.9.113.120, server: my.server, request: "GET /videos/videoId HTTP/1.1", upstream: "http://127.0.0.1:3000/videos/videoId", host: "www.my.host"

我试图增加超时时间

proxy_connect_timeout       600;
proxy_send_timeout          600;
proxy_read_timeout          600;
send_timeout                600;

但它没有帮助(

这是我的服务器配置。

server {
    listen x.x.x.x:443 http2;
    ssl on;

    server_name www.myservername.com;

...(ssl conf here)

    location / {
        proxy_pass http://localhost:3000;
        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;
    }
}

我在 StackOverflow 上挖掘了类似的主题,但没有找到解决方案。在这种情况下,最奇怪的是,在内部页面可用一段时间后,但在我进行加载测试并在生产服务器上发送大约 100 个请求后,它会停止工作大约半小时或一小时

提前感谢您的帮助。

【问题讨论】:

    标签: node.js nginx server nginx-reverse-proxy


    【解决方案1】:

    您正在使用 ssl 监听 443,您必须指定您的证书/密钥:

    server {
        listen 443 ssl;
        server_name www.example.com;
    
        ssl_certificate     /var/lib/nginx/ssl/serverssl.crt;
        ssl_certificate_key /var/lib/nginx/ssl/serverssl.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!MD5;
    
        location / {
            proxy_set_header Host example.com;
            proxy_pass http://localhost:8192/;
        }
     }
    

    【讨论】:

    • 当您直接从服务器 CURL 应用程序时,您有任何响应吗? curl -X GET "localhost:3002"
    • 不幸的是,curl 或 wget 也没有响应((((
    • 您的应用程序在端口 3000 或 3002 上运行(nginx 日志显示 3000,nginx conf 显示 3002)?重新启动您的应用程序,然后尝试使用 127.0.0.1 和 localhost 直接 curl/wget 您的应用程序(不是 nginx!):127.0.0.1:3000/videos/videoIdlocalhost:3000/videos/videoId
    • 如果你无法通过直接ip/lcoalhost访问你的应用程序,问题出在应用程序端而不是在nginx上
    • 配置中有错字。设置了 3000 端口。只是试图做卷曲,但无论如何都有同样的问题。 wget 或 curl 在我的机器上的本地主机上工作,但不在服务器上。
    猜你喜欢
    • 2011-04-08
    • 2019-09-29
    • 2016-06-19
    • 2011-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    • 2021-03-03
    相关资源
    最近更新 更多