1

I have a node.js application with socket.io running on an nginx server. The problem is the websocket connection gets timeouted by the nginx, 30 seconds after the connection, even though the connection doesn't remain idle for the whole time. This is my nginx.conf file;

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}


stream {
    upstream cluster {
        least_conn;
        server xx.xxx.xxx.xx:2157;
    }

    server {
        listen 7000;
        preread_timeout 86400s;
        proxy_timeout 86400s;
        proxy_pass cluster;
    }
}

The nginx version is: 1.12.2

Ümit Aparı
  • 540
  • 2
  • 6
  • 23
  • Have you ever got the websockets working? Is it not working at all or it worked and stopped after 30 seconds? – Rajan Panneer Selvam May 07 '18 at 20:50
  • The websockets are working just fine, there's no issues until it's 30 seconds past. 30 seconds after a client establishes the connection, nginx closes the websocket connection for that client forcefully, but the server remains on and accepts further connections (and timeouts them after 30 seconds too) – Ümit Aparı May 07 '18 at 20:55
  • Looks like a similar issue with timeout configuration: https://stackoverflow.com/questions/10550558/nginx-tcp-websockets-timeout-keepalive-config – Rajan Panneer Selvam May 07 '18 at 21:01
  • I've actually tried what was said on that post, but since it's an old post, and I am using the newest version of nginx right now, proxy_read_timeout directive isn't even supported on "stream"s anymore – Ümit Aparı May 07 '18 at 21:03

1 Answers1

1

PS: It was actually the node.js app itself that closes the connection of the client.

I've added this line of code io.set('heartbeat timeout', 24*60*60); to my node.js application and the timeout wasn't an issue anymore.

Ümit Aparı
  • 540
  • 2
  • 6
  • 23