Nginx: [error] recv() failed (104: Connection reset by peer) while reading response header from upstream
The upstream (PHP-FPM, Node, Gunicorn) closed the connection abruptly while Nginx waited for the response.
recv() failed (104: Connection reset by peer) while reading response header from upstream[error] recv() failed (104: Connection reset by peer) while reading response headerrecv() failed (104: Connection reset by peer) while reading upstream502 Bad Gateway connection reset by peer nginxupstream recv() failed (104 Meaning
The backend crashed, was restarted, hit a memory/timeouts limit, or max_requests recycled a worker mid-request. Check the app/PHP-FPM logs around that time (segfault, OOM, pm.max_requests), and align timeouts and keepalive settings between Nginx and the app.
Common causes
- Backend process crashed/segfaulted or OOM-killed
- Worker recycled (
pm.max_requests, gunicornmax_requests) - Backend timeout shorter than Nginx's
- Keepalive mismatch
- Deployment restart mid-request
⚡ Quick fix
- Check the backend log and
dmesg | grep -i killed - Raise backend memory/timeouts, review worker recycling
- Use
proxy_next_upstreamand graceful reloads for deploys
Detailed fix by platform
Linux
sudo tail -50 /var/log/php8.3-fpm.log; dmesg -T | grep -iE "killed process|segfault"
How to diagnose
- Backend — Crash in logs?
- OOM — dmesg?
- Recycle — max_requests?
🔧 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
- 499 Client Closed Request / client prematurely closed connection Nginx: [info] client prematurely closed connection while reading response header from upstream / access log status 499
- 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
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
- upstream timed out Nginx: upstream timed out (110: Connection timed out) while reading response header from upstream
- AH00558 Apache: AH00558: apache2: Could not reliably determine the server's fully qualified domain name
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