connect() failed (111: Connection refused) while connecting to upstream Nginx / Apache Origin: Edge & web server OSI layer 4 · Transport Last updated 5 Nov 2026

Nginx: [error] connect() failed (111: Connection refused) while connecting to upstream, upstream: "http://127.0.0.1:3000/"

Nginx tried to proxy a request but nothing listens on the upstream address, so the client gets 502.

Exact message you may see [error] connect() failed (111: Connection refused) while connecting to upstream, upstream: "http://127.0.0.1:3000/"502 Bad Gateway connect() failed (111 proxy_pass upstreamnginx proxy_pass upstream http connection refused 502
Seen on: Nginx Linux

Meaning

The backend (Node, Gunicorn, PHP-FPM TCP port) isn't running, listens on a different port/interface, or crashed. Start it, verify with ss -ltnp | grep 3000 and curl 127.0.0.1:3000. In Docker use the service name (not localhost) and ensure the container is healthy.

Common causes

  • Backend not running or crashed
  • Wrong port/host in proxy_pass
  • Backend bound to a different interface (IPv6 vs IPv4)
  • Docker networking (localhost)
  • Startup race after deploy

⚡ Quick fix

  1. Start the backend service and check its logs
  2. Match proxy_pass http://127.0.0.1:PORT; to the listener
  3. In Docker/K8s use the service name

Detailed fix by platform

Linux

  1. ss -ltnp | grep :3000; curl -I http://127.0.0.1:3000/

How to diagnose

  1. Listener — Port open?
  2. proxy_pass — Matches?
  3. Docker — Service name?

🔧 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…AH01114: HTTP: failed to make connection to backend — Apache: [proxy:error] AH00957: HTTP: attempt to connect to 127.0.0.1:3000 (127.0.0.1) failed / AH01114: HTTP: failed to make connection to backend: 127.0.0.1 (Nginx / Apache)AH01114: HTTP: failed…connect() to unix:/run/php/php-fpm.sock failed (13: Permission denied) — Nginx: [crit] connect() to unix:/run/php/php8.3-fpm.sock failed (13: Permission denied) while connecting to upstream (Nginx / Apache)connect() to unix:/ru…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…no resolver defined to resolve example.com — Nginx: [error] no resolver defined to resolve api.example.com, client: 203.0.113.5 (502 when proxy_pass uses a variable) (Nginx / Apache)no resolver defined t…connect()…

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.