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 upstreamin the error log. The app crashed, or is not listening on that port or socket. - PHP-FPM: the socket path in
fastcgi_passdoes 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; raiseproxy_buffer_size/fastcgi_buffer_size.upstream prematurely closed connection: the app crashed mid-request, or was killed for memory.
How to fix it
- Read
/var/log/nginx/error.logat the time of the 502: the line says which of these it is. - Check the app process (
systemctl status, the container, PM2) and restart it; then find out why it stopped. - Make
proxy_passorfastcgi_passmatch 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.
Often seen with
- 502 Bad GatewayThe server you reached works, but the application behind it did not answer properly.
- 403 Forbidden (nginx)nginx found the path but is not allowed to serve it.
- 404 Not Found (nginx)nginx looked for the page on disk, where the configuration says, and it is not there.