Skip to content
MtrXTools

upstream prematurely closed connection while reading response header from upstream

The backend closed the connection without answering

Seen in nginx error log (shown to visitors as 502 Bad Gateway)

nginx sent the request but the backend closed the connection before sending a complete response.

Common causes

  • The application crashed or a worker was killed mid-request (for example a gunicorn or uWSGI worker timeout, or out of memory).
  • The backend has a shorter timeout than nginx and gives up on slow requests.
  • A protocol mismatch, such as proxy_pass http:// to a port that expects HTTPS.

How to fix it

  1. Check the application logs at the same timestamp for crashes, killed workers or OOM messages.
  2. Align timeouts: the backend worker timeout should be at least as long as proxy_read_timeout.
  3. Confirm the scheme and port in proxy_pass match what the backend serves.

Got a different message? Paste it into the error explainer.

Related errors

All 19 Web servers & certificates errors