Skip to content
MtrXTools

connect() failed (111: Connection refused) while connecting to upstream

The backend is not listening

Seen in nginx error log (shown to visitors as 502 Bad Gateway)

nginx tried to connect to the proxy_pass or fastcgi_pass address and nothing was listening there.

Common causes

  • The application, PHP-FPM or container is stopped or crashed.
  • nginx points at the wrong port or socket path (for example an old php7.4-fpm.sock after a PHP upgrade).
  • The backend listens only on another address, e.g. 127.0.0.1 versus ::1, or inside a container network.

How to fix it

  1. Check the backend is running: systemctl status <service> or docker ps.
  2. Compare the upstream address in the log line with what is listening: ss -ltnp, or ls -l on the socket path.
  3. Correct proxy_pass or fastcgi_pass, then nginx -t and reload.

Got a different message? Paste it into the error explainer.

Related errors

All 19 Web servers & certificates errors