A 502 Bad Gateway error means a server acting as a gateway or proxy – a CDN, a load balancer, or the web server in front of PHP – received an invalid response from the server behind it. The site's front door is open, but the backend that builds the page failed. Most 502 errors are short-lived; repeated ones need fixing at the backend.
Before you start
- Note which page shows the 502 and what the error page looks like. A Cloudflare-branded page means Cloudflare is the gateway; a plain page means your server.
- cPanel access, or SSH for a VPS.
Common causes of a 502 Bad Gateway
- PHP processes crashing or being killed mid-request.
- Resource limits reached, so PHP workers are unavailable.
- A backend service stopped – PHP-FPM, Node.js app, or an upstream server on a VPS.
- CDN cannot read the origin's response (see Cloudflare 520 and 502 pages).
- Firewall blocking the proxy's requests to the backend.
How to fix it as a visitor
- Wait a minute and reload – a 502 during a restart clears quickly.
- Try a private window and another network to rule out local proxies.
How to fix it as a site owner on cPanel
- Check the error log in cPanel → Metrics → Errors for PHP fatal errors or crashes at the same time. See PHP errors and error_log.
- Check resource usage in cPanel → Metrics → Resource Usage. Entry process or memory faults mean the account is at its limit; see 508 resource limit reached.
- Disable the last plugin or change you made, then retest.
- Switch PHP version in Select PHP Version if a PHP extension crashes.
- For Node.js apps, restart the application in Setup Node.js App and check its log; see Node.js app errors.
How to fix it on a VPS
- Check the backend:
systemctl status php8.3-fpm(adjust the version) or your app service. - Read the web server error log for "upstream prematurely closed" or "connect() failed".
- Make sure socket paths and ports in the web server config match the backend. Our PHP-FPM 502 guide goes deeper.
Tip: If you use Cloudflare, test the origin directly with curl and --resolve. If the origin works, the 502 is between Cloudflare and your server, not inside it.
FAQ
Is a 502 error my fault?
Not as a visitor. For site owners it usually means a backend crash or limit.
How is 502 different from 504?
502: the backend gave a bad answer. 504: the backend took too long to answer.
Does a 502 hurt SEO?
Brief ones do not. Hours of 502s can cause pages to drop temporarily.
