upstream prematurely closed connection while reading response header Nginx / Apache Origin: Edge & web server OSI layer 7 · Application Last updated 5 Nov 2026

Nginx: [error] upstream prematurely closed connection while reading response header from upstream

The backend ended the connection before sending a complete response header.

Exact message you may see upstream prematurely closed connection while reading response header from upstream[error] upstream prematurely closed connection while reading response header502 Bad Gateway upstream prematurely closed connectionupstream prematurely closed FastCGI stdout while reading response header from upstreamupstream prematurely closed connection while reading upstream
Seen on: Nginx Linux

Meaning

Usually the app/PHP-FPM worker crashed (fatal error, segfault, memory limit) or exited, or a proxy timeout/keepalive race closed the socket. Check PHP-FPM/app logs for fatal errors, request_terminate_timeout, max_execution_time and OOM kills.

Common causes

  • PHP fatal/segfault or exit() mid-request
  • Worker killed by OOM or timeout (request_terminate_timeout)
  • Backend keepalive closed the idle connection (race)
  • Wrong protocol (HTTP to a TLS/FastCGI port)
  • App crashed on large payloads

⚡ Quick fix

  1. Read the app/PHP-FPM error log for the crash
  2. Align timeouts; disable/adjust backend keepalive
  3. Check dmesg for OOM kills

Detailed fix by platform

Linux

  1. sudo journalctl -u php8.3-fpm --since "10 min ago" | tail -30

How to diagnose

  1. Backend log — Fatal or crash?
  2. Timeouts — request_terminate_timeout?
  3. Protocol — Correct?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Edge & web server. Errors that are often confused with or caused by this one (click to open):

502 — HTTP 502 Bad Gateway (HTTP)502AH00898: Error reading from remote server (502 Proxy Error) — Apache: [proxy_http:error] AH01102: error reading status line from remote server 127.0.0.1:3000 / AH00898: Error reading from remote server returned by /api (Nginx / Apache)AH00898: Error readin…connect() failed (111: Connection refused) while connecting to upstream — Nginx: [error] connect() failed (111: Connection refused) while connecting to upstream, upstream: "http://127.0.0.1:3000/" (Nginx / Apache)connect() failed (111…nginx: host not found in upstream — Nginx: nginx: [emerg] host not found in upstream "app" in /etc/nginx/conf.d/default.conf:5 (Nginx / Apache)nginx: host not found…no live upstreams while connecting to upstream — Nginx: [error] no live upstreams while connecting to upstream (503/502) (Nginx / Apache)no live upstreams whi…recv() failed (104: Connection reset by peer) while reading response header — Nginx: [error] recv() failed (104: Connection reset by peer) while reading response header from upstream (Nginx / Apache)recv() failed (104: C…upstream timed out — Nginx: upstream timed out (110: Connection timed out) while reading response header from upstream (Nginx / Apache)upstream timed outupstream …

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.