Application process is down
PHP-FPM, Node, Gunicorn or another app server crashed, was killed for memory or never restarted after a deploy.
Monitor
Protect
Manage
By role
Security
Renewals
Monitoring
A 502 Bad Gateway means a server acting as a gateway or proxy, such as nginx, a load balancer or a CDN, received an invalid response from the server behind it. The fault is almost always upstream of the proxy: a crashed or unreachable application server.
| Code | Meaning | Typical cause |
|---|---|---|
| 502 Bad Gateway | The gateway received an invalid response from upstream | Upstream crashed, refused the connection or sent a malformed reply |
| 503 Service Unavailable | The server is temporarily unable to handle the request | Overload or planned maintenance, often with a Retry-After header |
| 504 Gateway Timeout | The gateway did not get a response from upstream in time | Slow upstream: a long query, a hung process or a timeout set too low |
Definitions follow RFC 9110, section 15.6.
Work from the application outward. The cause is nearly always one of these.
PHP-FPM, Node, Gunicorn or another app server crashed, was killed for memory or never restarted after a deploy.
The proxy points at a socket or port nothing listens on, often after a config change or version upgrade.
The app server hits a worker limit or request limit and drops the connection mid-response.
A proxy that resolves the upstream name once at startup keeps using a stale or missing address.
The proxy speaks HTTPS to an origin that only serves HTTP, or the origin certificate is invalid.
A firewall or rate limit blocks the CDN's IP ranges, so every request through the CDN fails.
Reload to rule out a blip. Then request the origin server by IP or its internal URL, bypassing the CDN or load balancer. If the origin works directly, the fault is in the proxy layer.
Confirm the app server is running, for example with systemctl status php8.3-fpm or your process manager. Restart it and watch whether it stays up.
The log names the failure. A refused connection, a reset connection and a premature close each point to a different cause (see the log lines below).
Compare the proxy_pass or fastcgi_pass target with the socket path or port the app server really listens on.
Out-of-memory kills, exhausted worker pools and low request limits all make the app server drop connections under load.
A deploy, a package upgrade, a firewall rule or a CDN setting that changed shortly before the first 502 is the likeliest cause.
connect() failed (111: Connection refused) while connecting to upstream
-> nothing is listening at the upstream address: app server down or wrong port
upstream prematurely closed connection while reading response header from upstream
-> the app server accepted the request, then died or closed the connection
recv() failed (104: Connection reset by peer) while reading response header from upstream
-> the upstream reset the connection, often a crash or a limit being hit
connect() to unix:/run/php/php8.3-fpm.sock failed (2: No such file or directory)
-> the socket path is wrong or the service is not runningUpstream behaviour is configured with the directives in the nginx proxy module documentation.
Intermittent 502s usually mean the app server is crashing and restarting, or hitting a worker or memory limit under load. Check the application log and system memory at the time of the errors, and confirm the problem from more than one location, because one failing request tells you little. Aepto can check a site from several regions and alert you when it starts failing.
No. A 502 is a server-side error, so nothing on your device or connection causes it. Reload once, try again in a few minutes, and contact the site owner if it persists. Clearing cache rarely helps, because the failing request never reaches the page content.
Yes, when it comes from a brief upstream restart or a deploy in progress. A 502 that lasts more than a few minutes points to an application server that is down or misconfigured and needs someone to fix it.
A short 502 does little harm, because Google retries later. Google has said 5xx errors that persist can cause pages to drop out of the index over time, so repeated or lasting 502s are worth fixing and monitoring.
A 502 means a gateway received an invalid upstream response. Cloudflare reports its own 52x codes, such as 520 for an unknown or empty origin response, so a Cloudflare error code points to the origin as well but gives more detail about how it failed.
Monitor the site with an uptime check that alerts you on any 5xx response, ideally from more than one region and at a short interval, so a failing origin is caught within minutes instead of through support tickets.
Aepto checks your sites from up to six regions, as often as every minute on paid plans, and alerts you when one starts failing.