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 streams drop idle connections after ten minutes

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

proxy_timeout 1h;

Keeps idle TCP and UDP streams open longer than the ten minute default.

Streams are the part of NPM people forget about: plain TCP or UDP forwarding, no HTTP involved. An SSH session or a database link through one can die when you leave it alone.

Nginx’s stream proxy has a proxy_timeout that defaults to 10 minutes. It closes the connection when no data moves in either direction for that long. NPM includes server_stream.conf from /data/nginx/custom/ in every stream server block, so you can change it there:

# /data/nginx/custom/server_stream.conf
proxy_timeout 1h;

Do not forget the other half of streams: the port must be published on the container too. The setup page has a commented-out line for it in the compose file, for example - '21:21'.

Caveat: the file applies to every stream, TCP and UDP alike. If you need it for only one kind, server_stream_tcp.conf and server_stream_udp.conf exist for exactly that. And a long timeout keeps dead connections around longer, so I would use a value I can explain, not a huge one.

I find streams the least understood part of NPM, probably because the UI hides how much nginx is doing underneath.

Further reading: nginx.org: ngx_stream_proxy_module, Nginx Proxy Manager: Setup, On this site: tell Nginx which proxy to trust, so your apps see the real client IP, On this site: nginx closes a quiet WebSocket after 60 seconds

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