Skip to content

Errors / HTTP errors

502 Bad Gateway nginx

nginx is running, but the application it passes requests to did not answer properly.

The whole site behind that nginx, or the routes it proxies, fails.

Seeing it on someone else’s site?

  • The site's server is misbehaving; it is not your connection. Try again in a few minutes.

Why it happens, if it is your site

  • The upstream is down: connect() failed (111: Connection refused) while connecting to upstream in the error log. The app crashed, or is not listening on that port or socket.
  • PHP-FPM: the socket path in fastcgi_pass does not match the one in the pool config, or its permissions do not let nginx connect.
  • upstream sent too big header while reading response header from upstream: large cookies or headers; raise proxy_buffer_size / fastcgi_buffer_size.
  • upstream prematurely closed connection: the app crashed mid-request, or was killed for memory.

How to fix it

  1. Read /var/log/nginx/error.log at the time of the 502: the line says which of these it is.
  2. Check the app process (systemctl status, the container, PM2) and restart it; then find out why it stopped.
  3. Make proxy_pass or fastcgi_pass match exactly where the app listens.

Whose problem it is

Usually the server that answers the request.

Does your site have it?

Free, no account. We open your page and four more in a clean Chrome and list every error like this one, with the page and the click that caused it. How the free page check works.

Check only sites you run or have permission to check.

Often seen with