Nginx: [error] upstream prematurely closed connection while reading response header from upstream
The backend ended the connection before sending a complete response header.
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 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
- Read the app/PHP-FPM error log for the crash
- Align timeouts; disable/adjust backend keepalive
- Check
dmesgfor OOM kills
Detailed fix by platform
Linux
sudo journalctl -u php8.3-fpm --since "10 min ago" | tail -30
How to diagnose
- Backend log — Fatal or crash?
- Timeouts — request_terminate_timeout?
- 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:
Similar errors
- 502 HTTP 502 Bad Gateway
- AH00898: 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
- 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/"
Most viewed in Nginx / Apache
- nginx: [emerg] unknown directive Nginx: nginx: [emerg] unknown directive "x" in /etc/nginx/sites-enabled/x:12 — configuration file test failed
- AH00558 Apache: AH00558: apache2: Could not reliably determine the server's fully qualified domain name
- AH00072: make_sock: could not bind to address 0.0.0.0:80 Apache: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80 / AH00015: Unable to open logs
Other ways to find it
Where this error sits
Origin: Edge & web server. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 5 Nov 2026