How to fix a 502 bad gateway error on your website
A 502 Bad Gateway error means a server in front of your site (such as a proxy, CDN or web server) got a broken or empty reply from the server behind it. It is usually fixed by restarting or repairing that back end, often a crashed PHP process, an overloaded host or a faulty plugin.
A 502 Bad Gateway error means one server on the way to your website asked another server for the page and got an invalid answer, or none at all. Visitors see a plain page saying 502 Bad Gateway, HTTP Error 502 or 502 Service Temporarily Unavailable, or a branded error page from your host or from Cloudflare. Your content is normally still there. The part that builds the page has stopped responding properly.
Why it matters
While the error shows, nobody can buy, book or contact you through the site. Visitors rarely retry, they go to a competitor. Search engines treat a short outage as temporary, but if Google meets 502 errors repeatedly over days, it may crawl your site less often and can eventually drop pages from results. A site that errors often also looks unreliable, which costs trust even after it comes back.
How to check if your site has it
Start with the simple, free checks:
- Reload the page after a minute. Many 502 errors last only seconds.
- Open the site on your phone using mobile data, not Wi-Fi. This rules out a problem with your own network or browser cache.
- Try a free tool such as Down For Everyone Or Just Me to see if the site is down for others too.
- Try several pages. If only one page fails, the cause is probably a slow or broken script on that page. If every page fails, the whole back end is affected.
- Check your host's status page for a known outage.
If you are comfortable with a terminal, this shows the status code your site returns:
curl -I https://example.com
Look at the first line. HTTP/2 502 confirms the error. Also look at the server header: a value like cloudflare tells you the error passed through Cloudflare.
Because 502 errors often come and go, you may not be at your computer when it happens. An uptime monitor that checks every few minutes is the reliable way to catch them. SiteMonday's week 29 uptime monitoring report is one example.
How to fix it in general
Work from the simplest cause to the most involved one.
- Wait a few minutes and reload. If your host is restarting a service or you are on a traffic spike, it may clear on its own.
- Clear caches. Clear your browser cache, and any cache plugin or server cache your host offers.
- Check for a CDN or firewall problem. If you use Cloudflare or a similar service, pause it for a short time (this removes its protection and may expose your server while paused, so turn it back on afterwards) or look at its error page. If the site works with the CDN paused, the CDN cannot reach your server, often because a firewall on the server is blocking the CDN's addresses.
- Look at the error log. In your hosting panel, find
LogsorError log. On Nginx servers the file is usually/var/log/nginx/error.log. Messages such asupstream prematurely closed connection,connect() failedorupstream timed outpoint to a crashed or overloaded back end. - Restart the back end. On shared hosting, ask support to restart PHP and the web server. On a server you control, restart the PHP service (often called PHP-FPM) and the web server.
- Disable recent changes. A new plugin, theme or update is a very common trigger. Turn off the last thing that changed.
- Check resources. If the host is out of memory, CPU or PHP workers, pages time out and the proxy returns 502. Your hosting dashboard usually shows usage.
- Contact your host. Send them the time of the error and any log lines. They can see problems you cannot.
Fixes for common platforms
WordPress. The usual culprit is a plugin or theme crashing PHP. Connect by FTP or your host's file manager and rename wp-content/plugins to plugins-off. If the site returns, rename it back and then rename plugin folders one by one to find the guilty one. If that does not help, switch to a default theme by renaming your active theme's folder. Also check the PHP memory limit and PHP version in your hosting panel. There is a longer walkthrough in the WordPress 502 guide.
Cloudflare. The error page tells you whether the problem is between the visitor and Cloudflare or between Cloudflare and your server. If your server is the source, fix it as above. Make sure your server's firewall allows Cloudflare's published IP ranges. See the Cloudflare 502 guide.
Nginx or Apache with PHP. Check that PHP-FPM is running and that the socket or port named in the Nginx fastcgi_pass setting matches the one PHP-FPM listens on. After a PHP upgrade, the socket file name often changes, which causes an immediate 502.
Managed hosts and control panels. Plesk, WP Engine, AWS load balancers and Laravel Forge setups all have their own places to restart services and read logs. The menu names depend on your plan and version, so look for Logs, Services or Health pages.
How to confirm the fix worked
Do not stop at one successful page load.
- Run
curl -Ion your home page and a few inner pages. You wantHTTP/2 200. - Test the pages that do the most work: checkout, search, contact forms and the admin login.
- Test from a different network, such as mobile data.
- Watch the error log for a while. New
upstreamerrors mean the cause is not fully gone. - Keep an eye on the site for the next day or two, since intermittent causes like memory limits can return.
How to stop it coming back
- Monitor uptime so you hear about errors before customers do. If outages keep recurring, read why a website keeps going down.
- Update with care. Back up first, and test plugin or theme updates on a staging copy when your host offers one.
- Match hosting to your traffic. If errors appear during busy periods, you probably need more memory or PHP workers, or better caching.
- Remove plugins you do not use, and replace ones that regularly slow or crash the site.
- Keep notes of what changed and when. When a 502 appears, the last change is the first suspect.
Finding the cause is only half the job. SiteMonday reports the downtime it sees, but the fix itself is up to you or your developer.
Step by step for your platform
- 502 bad gateway error on Nginx
- 502 bad gateway error on Cloudflare
- 502 bad gateway error on WordPress
- 502 bad gateway error on AWS
- 502 bad gateway error on WP Engine
- 502 bad gateway error on Laravel
- 502 bad gateway error on Plesk
Questions
What does 502 Bad Gateway mean in simple terms?
A server that sits between your visitor and your website could not get a valid reply from the server that builds the page. It is a server side problem, not something wrong with the visitor's device.
Is a 502 error my fault or my host's fault?
It can be either. Hosting overload and outages are the host's side, while a faulty plugin, bad configuration or blocked CDN is usually on your side. The error log and your host's support can tell you which.
Will a 502 error hurt my Google rankings?
A short one will not. Repeated or long lasting 502 errors can make Google crawl less and may lead to pages dropping out of results until the site is stable again.
Why does the 502 error come and go?
Intermittent 502 errors usually point to a back end that is overloaded or running out of memory, so it fails only under load. A process that crashes and restarts automatically can cause the same pattern.
Can I fix a 502 error without a developer?
Often yes. Reloading, clearing caches, pausing your CDN, and disabling plugins by renaming folders are all doable without code. If the logs point at server configuration, ask your host or a developer.
What is the difference between 502, 503 and 504 errors?
A 502 means the gateway got an invalid reply, a 503 means the service is unavailable or overloaded, and a 504 means the gateway waited too long and timed out. They often have related causes, so the same checks help.