Http request timeout after 2 minutes in bad NGINX 502 gateway in Node application

I scratched my head on this timeout issue and hope to get some tips. I have an HTTP request that may take 2.5 minutes to return a response. I have a timeout in Angular for 3 minutes and NodeJS for 3 minutes. My nginx setup has a timeout of 200 seconds, and the connection timeout of the elastic load balancing is set to 4 minutes. However, I always see the 502 bad gateway nginx 1.4.6 (Ubuntu) error with an accuracy of 2 minutes. Is there any part that I skip to have a longer timeout?

My nginx setup:

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 setup uses connection timeout

var timeout = require('connect-timeout');
app.use(timeout(300000));
+3
source share
1

, , : node http 120- -. - :

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

  // ... do the real work

  res.json(...);
}

0, .

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

: https://forum.nginx.org/read.php?2,214230,214239#msg-214239

+1

Source: https://habr.com/ru/post/1689966/


All Articles