recv() failed (104: Connection reset by peer) while reading response header Nginx / Apache Origin: Edge & web server OSI layer 4 · Transport Last updated 5 Nov 2026

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.

Exact message you may see 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
Seen on: Nginx Linux

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, gunicorn max_requests)
  • Backend timeout shorter than Nginx's
  • Keepalive mismatch
  • Deployment restart mid-request

⚡ Quick fix

  1. Check the backend log and dmesg | grep -i killed
  2. Raise backend memory/timeouts, review worker recycling
  3. Use proxy_next_upstream and graceful reloads for deploys

Detailed fix by platform

Linux

  1. sudo tail -50 /var/log/php8.3-fpm.log; dmesg -T | grep -iE "killed process|segfault"

How to diagnose

  1. Backend — Crash in logs?
  2. OOM — dmesg?
  3. 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:

Where this error sits

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

499 Client Closed Request / client prematurely closed connection — Nginx: [info] client prematurely closed connection while reading response header from upstream / access log status 499 (Nginx / Apache)499 Client Closed Req…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…ModSecurity: Access denied with code 403 — Nginx/Apache: ModSecurity: Access denied with code 403 (phase 2). Matched "Operator GE matched 5 at TX:anomaly_score" (Nginx / Apache)ModSecurity: Access d…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…upstream prematurely closed connection while reading response header — Nginx: [error] upstream prematurely closed connection while reading response header from upstream (Nginx / Apache)upstream prematurely …recv() fa…

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.