Websocket disconnects after hours; reconnect fails unless new tab or service restart (Nginx reverse proxy)
05:47 29 Dec 2025

I use Nginx as a reverse proxy for a websocket. After running for hours, the websocket connection drops. Reconnect from the same tab fails, but opening a new browser tab connects immediately. Temporary workaround: restart the websocket service. The websocket service logs show no errors.

Environment

  • OS: Linux Ubuntu 18
  • Nginx
  • WS upstream: Node.js websocket
  • Frontend: React.js

Configuration

# /etc/nginx/conf.d/01-ucan-socket.conf
upstream ucan-socket {
    server localhost:8080 max_conns=100;
}

# /etc/nginx/conf.d/10-ucan.conf (TLS server)
location /ws {
    proxy_pass http://ucan-socket;
    proxy_http_version 1.1;
    proxy_set_header Upgrade "websocket";
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
}

Global proxy settings:

# /etc/nginx/conf.d/00-proxy-settings
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 10m;
keepalive_timeout 5 5;

Nginx log (example)

[error] ... no live upstreams while connecting to upstream, request: "GET /ws HTTP/1.1", upstream: "http://ucan-socket/ws"

In access/APM logs:

  • /ws has many status=404 but upstream_status=502
  • successful 101 connections can stay open for a long time (request_time tens of thousands of seconds)

What I tried

  • Restart websocket service -> works again
  • Open a new browser/tab -> connects immediately
  • Websocket service appears healthy in application logs

Question What is the most likely cause of no live upstreams here? Can max_conns=100 make Nginx treat the upstream as down when websocket connections stay open? What Nginx settings should I change to keep websocket stable 24/7 and allow reconnects (timeouts, keepalive, buffering, upgrade headers, etc.)?

reactjs node.js nginx websocket