简体   繁体   English

在Node应用程序的NGINX 502坏网关中,Http请求超时2分钟

[英]Http request timeout at 2 minutes in NGINX 502 bad gateway in Node app

I'm been scratching my head on this timeout issue and hope to get some helps. 我一直在抓住这个超时问题并希望得到一些帮助。 I have a http request that might take 2.5 minutes to return the response. 我有一个http请求可能需要2.5分钟才能返回响应。 I have timeout handling in Angular for 3 minutes, and NodeJS for 3 minutes as well. 我在Angular中处理超时处理3分钟,NodeJS处理3分钟。 My nginx setting have 200 seconds timeout and my Elastic Load Balancing Connection Timeout is set to 4 minutes. 我的nginx设置有200秒超时,我的Elastic Load Balancing连接超时设置为4分钟。 However, I keep seeing the 502 bad gateway nginx 1.4.6 (Ubuntu) error at exact 2 minutes. 但是,我一直在2分钟内看到502坏网关nginx 1.4.6(Ubuntu)错误。 Is there any part that I miss to have longer timeout? 有没有我错过超时的部分?

My nginx setting: 我的nginx设置:

server {
    listen 80;
    server_name;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log debug;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header Connection "";
        proxy_http_version 1.1;
        proxy_pass http://localhost:8060;
        proxy_redirect off;
        proxy_connect_timeout 200s;
        proxy_send_timeout 200s;
        proxy_read_timeout 200s;
        send_timeout 200s;
    }
    #Handle protected assets using 'internal' directive documented here: https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/
    location /protected {
        internal;
        expires -1;
    }
}

My NodeJS setting is using connect-timeout 我的NodeJS设置正在使用connect-timeout

var timeout = require('connect-timeout');
app.use(timeout(300000));

I just came across this today, and probably found an answer - there is 120 s hard coded timeout in node's http module. 我今天刚刚遇到这个问题,并且可能找到了答案 - 节点的http模块中有120秒的硬编码超时。 I had to set socket timeout in given request handler like this: 我不得不在给定的请求处理程序中设置socket超时,如下所示:

yourHandler(req, res) {
  req.socket.setTimeout(3600e3); // 1 hour

  // ... do the real work

  res.json(...);
}

You can also set this limit to 0 to disable this timeout. 您也可以将此限制设置为0以禁用此超时。

https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback

originally found the answer here: https://forum.nginx.org/read.php?2,214230,214239#msg-214239 最初在这里找到答案: https//forum.nginx.org/read.php?2,214230,214239#msg-214239

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM