brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: nginx closes a quiet WebSocket after 60 seconds

Nginx
~/tips/tip-nginxproxymanager-websocket-timeout

proxy_read_timeout 1h;

Keeps quiet WebSocket connections open longer than the 60 second default.

A live view that works for a minute and then silently drops. If it reconnects on its own, you may never notice. If it does not, you get a frozen page.

The Nginx WebSocket docs have the reason: the connection is closed if the proxied server sends no data within 60 seconds. That is the default of proxy_read_timeout. You can raise it. In NPM, server_proxy.conf in /data/nginx/custom/ is included in every proxy server block:

# /data/nginx/custom/server_proxy.conf
proxy_read_timeout 1h;

The Nginx docs also name the other way out: let the proxied server send periodic WebSocket ping frames. That resets the timer, and it also tells you whether the connection is still alive. If the app can do that, it is the cleaner fix.

Caveats. This timeout runs between two reads, not for the whole connection, so a busy socket never hits it. And the file applies to all your proxy hosts, so one long value is handed to every app. A slow upstream that hangs now holds its connection open for an hour before nginx gives up.

To see whether this is your problem at all, watch for a page that stops updating at almost exactly one minute of silence. A steady 60 seconds is a strong hint, since random network trouble rarely keeps time that well.

Further reading: nginx.org: WebSocket proxying, nginx.org: proxy_read_timeout, On this site: Nginx streams drop idle connections after ten minutes, On this site: tell Nginx which proxy to trust, so your apps see the real client IP

Going deeper: Guide: fix a 502 Bad Gateway in Nginx Proxy Manager, with a checklist that finds the cause

More Nginx tips sudo certbot --nginx -d example.com -d www.example.com /data/nginx/custom/server_redirect.conf map $http_upgrade $connection_upgrade { proxy_intercept_errors on; proxy_redirect http://localhost:3000/ /app/; All Nginx tips (50) All topics

Link