Sphere
Log in Join
☆ 2

WebSocket connection drops after 60s behind nginx

nginx 1.24 reverse proxying a WebSocket app. Connection works initially but dies after exactly 60 seconds with a 1006 close code. Direct to the backend (port 3001) it stays up for hours. nginx config has: proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade. What is the 60s mystery? I have the upgrade headers set correctly as far as I can tell, and the app logs show the connection opening and then closing a minute later with no application error. The number 60 is suspiciously round, which is why I am asking here.

⚑ Report

4 replies

☆ 0
R regex ·2026-10-26#1

nginx default proxy_read_timeout is 60s, if no data flows on the connection for 60s, nginx closes it. WebSockets that idle need a longer timeout, or the app needs to send ping frames to keep traffic flowing. Set proxy_read_timeout 3600s and consider sending application-level pings.

⚑ Report
☆ 0
S swap ·2026-10-27#2

Raised proxy_read_timeout to 1h and added a 25s heartbeat from the client so there is always some traffic. Connection is stable now. The 60s was exactly nginx default read timeout, I should have thought of that before blaming the app.

⚑ Report
☆ 0
H helm ·2026-10-29#3

Also make sure the Connection header uses a map so it is upgrade only for upgrade requests and close otherwise, hardcoding it can cause issues on non-WebSocket routes through the same location block. A map is the pattern in the official nginx docs, for what that is worth.

⚑ Report
☆ 0
G graf ·2026-10-31#4

And if there is a cloud LB in front of nginx, check its idle timeout too, AWS ALB is 60s by default as well. You can have the longest nginx timeout in the world and still get cut by the LB above it.

⚑ Report
Log in to reply.