Interview Prep/Networking/Load balancers and reverse proxies

nginx logs `upstream prematurely closed connection while reading response header from upstream`.

IntermediateTroubleshootingLoad balancers and reverse proxies
Answer

Likely causes → The upstream accepted the request and then closed the connection without sending a full response: the app worker crashed (OOM, segfault), hit its own timeout (gunicorn --timeout, PHP-FPM request_terminate_timeout), or closed a reused keepalive connection.

Diagnose →

grep 'prematurely closed' /var/log/nginx/error.log | tail
journalctl -u myapp --since '10 min ago' | grep -iE 'killed|timeout|worker'
dmesg -T | grep -i 'out of memory'

Fix → Fix the crash or raise the app's worker timeout above proxy_read_timeout if long requests are legitimate. If it's keepalive-related, raise the upstream's keepalive timeout or set proxy_next_upstream error timeout; for idempotent requests.

Prevent → Align app worker timeouts with proxy timeouts, and alert on worker restarts.

All Networking questions Roadmap: Networking for DevOps

More on Load balancers and reverse proxies