FULL AI ANALYSIS

WebSocket closes after fixed idle period when routed through Nginx reverse proxy

Generated Nov 8, 2026, 9:38:46 AM

Analysis summary

Common causes: Nginx proxy timeouts (proxy_read_timeout, proxy_send_timeout, keepalive_timeout), missing proxy headers or websocket-specific directives, upstream idle timeouts at load balancer or NAT, or lack of TCP keepalives. Diagnosis should confirm which hop is closing the connection and whether periodic pings prevent the drop.

Possible causes

Intermediate load balancer/NAT closes idle TCP connections after a fixed timeout

75%

Nginx proxy has an idle timeout (proxy_read_timeout/keepalive_timeout) lower than observed lifetime

70%

Backend not sending periodic pings and client not configured to respond, leading intermediates to treat connection as idle

65%

Incorrect websocket proxy config (missing Upgrade/Connection headers) causing subtle negotiation issues that later tear down

40%

Suggested fixes

1

Diagnostic step 1

Enable debug logging on Nginx (error_log with debug) and capture the proxy TCP flow around disconnect time; correlate timestamps with backend and client logs. Result meaning: If Nginx logs an idle timeout or explicitly closes the upstream, it indicates proxy timeout. If Nginx shows no activity and backend logs show abrupt TCP FIN/RST, an intermediate (LB/NAT) likely closed the connection.

2

Diagnostic step 2

Use tcpdump or ngrep on the proxy host to capture TCP packets for the websocket connection across the disconnect interval. Result meaning: If a FIN/RST originates from the proxy host, proxy is closing. If packets show no FIN until client reports close, then an intermediate device may be dropping idle flows or injecting RSTs.

3

Diagnostic step 3

Temporarily configure the backend or client to send application-level pings every 20–30s (ws.ping or websocket ping frames) and observe whether connection stays up beyond previous timeout. Result meaning: If pings prevent disconnects, an idle-flow timeout on an intermediate device or proxy is likely. If pings do not help and logs show closed from proxy, adjust proxy timeouts instead.

4

Diagnostic step 4

Verify Nginx websocket proxy directives: proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; map $http_upgrade $connection_upgrade { default upgrade; '' close; } Result meaning: If these directives are missing, the handshake may be downgraded or not kept-alive properly. Correct config should maintain upgrade and reduce protocol-level issues.