The “502 bad gateway” WordPress error is one of the most common errors that occur on websites. Fixing this error is not easy though, because it can be tough to pinpoint the exact cause.
To figure out what caused the 502 error, several solutions have to be tried out until you hit the bull’s-eye.
But before you start with the solutions, it’s absolutely essential that you understand what the 502 error means. It’s akin to learning what an ailment or disease is before figuring out the cause and remedy.
Let’s begin…
When you open a website, here’s what happens behind the scenes:
The browser sends a request to the hosting server. Normally the server will respond with HTTP (HyperText Transfer Protocol) status codes and the resources (or page) you requested. But sometimes the server may respond with a 502 error. It typically happens when the server takes a long time to fetch the page.
This delay in response could have occurred because of reasons like a server issue, plugin conflict, DNS, PHP issues, etc.
Impact of the “502 bad gateway” error
The 502 error affects your visitors as they are unable to get the information they came for. As a result, they abandon your website quickly.
Search engines will notice this behavior and soon enough your rankings will drop. Needless to say, this chain of events will cause a significant dip in your revenue collection.
Causes of “502 bad gateway” error
Now that we’ve talked a bit about what a 502 bad gateway error is in WordPress, let’s look at the most common causes.
- Server issues
- Poorly coded plugins and/or themes
- PHP timeout issues
- CDN issues
- Browser issues
- DNS issues
- Hardware connectivity issues
1. Server issues
The server where your website is hosted could be down.
This is not unusual.
The hosting server could have been taken offline intentionally for maintenance purposes, like updating the server’s security system.
![502 bad gateway error with WordPress can occur when servers are taken offline. Bluehost shares a maintenance email to prepare customers](https://mllj2j8xvfl0.i.optimole.com/cb:jC7e.37109/w:942/h:695/q:90/f:avif/https://themeisle.com/blog/wp-content/uploads/2021/06/bluehost-maintenance-error.png)
A hosting server is a piece of complex equipment that may be damaged and require replacement or repairs. If your hosting server is undergoing repairs, then you are likely to see a 502 error on your website.
There is a chance that high traffic to your website caused server overload and rendered it unable to respond.
2. Poorly coded plugins and/or themes
Themes and plugins are what make WordPress so popular. But themes and plugins are also the reason why a website crashes or throws an error sometimes.
We have seen far too many poorly coded themes or plugins overwhelming the server which then throws a 502 error.
3. PHP timeout issues
PHP is a programming language. In fact, all plugins and themes contain a bunch of PHP files. When you install or update a plugin or theme, some of these PHP files start running.
PHP code can run for a long time and use a significant chunk of your hosting server’s resources. To prevent abuse of server resources, hosting providers put a cap on how long a PHP code can run. When the code hits the limit, the server throws a 502 error.
4. CDN server issue
CDN (Content Delivery Network) helps make your website faster. Some CDNs, like Cloudflare, focus heavily on security; therefore, they also offer firewall protection.
Since a CDN sits between your hosting server and the browser, any request made on your website will first have to pass through the CDN.
So when you open your website while the CDN server is down, your request will generate a 502 error.
5. Browser issue
Occasionally, browsers throw 502 errors too. This typically happens because of a corrupt extension, like ad-blockers, corrupt cache, or outdated browser.
6. DNS error
DNS issues are rare. They occur when you switch domain registrars or hosting providers. This can also occur when you are setting up a web application firewall like Cloudflare or Sucuri.
Following a migration or firewall installation, you need to change the DNS nameservers and point them to your web host. It can take up to 24 hours for the nameservers to activate. If you open the website during this period, you are going to be welcomed with a 502 error.
7. Hardware & connectivity issues
On rare occasions, the 502 error occurs due to hardware or broadband connectivity issues. Most of the time, it’s a temporary glitch.
That’s all, folks!
How to remove the “502 bad gateway” WordPress error from your website?
Now that you have an idea of what could be causing the “502 bad gateway” error, let’s look at some of the possible solutions.
⚠️ We recommend: Make a backup of your entire website. In the following tutorial, you will be dealing with the wp-config
file which is a core WordPress file. You wouldn’t want to add to your trouble by messing up a core file. Make a backup. If things go south, you can simply restore the backup and start all over again.
- Clear cache
- Fixing hardware connectivity issues
- Check your error log
- Fixing server issues
- Fixing poorly coded plugins and themes
- Fixing browser issues
- Fixing CDN server issues
- Fixing DNS issues
- Fixing PHP timeout issues
1. Clear cache
Quite often we have found that WordPress errors are nothing but a temporary glitch.
So, it’s possible that the error may have been automatically resolved, but you are still seeing it because your browser or WordPress is showing a cached version of your website. Therefore, clear your browser and website cache. And then, refresh the page.
We cover how to clear your browser cache in detail in the following guide. When it comes to clearing your website cache, the exact place where you can do that will depend on the caching plugin that you’re using. Read more about this here.
![clearing chrome cache](https://mllj2j8xvfl0.i.optimole.com/cb:jC7e.37109/w:634/h:586/q:eco/f:avif/https://themeisle.com/blog/wp-content/uploads/2021/06/clearing-chrome-cache.png)
2. Fixing hardware & connectivity issues
Sometimes, the solution to a seemingly complex issue is as simple as restarting your PC and router to fix it. Try that.
3. Check your error log
You can take advantage of the error logs to narrow down the issue. All you need to do is enable logging by adding this code to your wp-config.php
file:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
![inserting code in wpconfig file](https://mllj2j8xvfl0.i.optimole.com/cb:jC7e.37109/w:770/h:454/q:eco/f:avif/https://themeisle.com/blog/wp-content/uploads/2021/06/editing-wpconfig-file.png)
A file called debug.log
will appear in your wp-content
directory. Open it, and it should tell you what’s causing the 502 Bad Gateway error.
4. Fixing server issues
Check whether your hosting servers are down by using one of these tools: Down or Not, or Is It Down Right Now, or Down For Everyone or Just Me.
The server could have been taken offline for maintenance purposes. In that case, you should have received an email informing you about when the server will be up again.
Even if your hosting servers are up, speak to your hosting provider. Find out whether it’s a server issue and then fix it.
5. Fixing poorly coded plugins and themes
The truth is, you can’t fix poorly coded plugins and themes because you didn’t build them. What you can do is disable them. But how do you know which ones to disable?
Disable all the plugins and themes one by one. And check your website simultaneously.
When you see that the error is gone, you’d know which plugin or theme caused it.
We strongly recommend that you carry out this exercise on a staging site to prevent damaging your live website further.
6. Fixing browser issue
Open your website on different browsers. If the error persists then follow the instructions below.
There are three common browser issues that WordPress users typically face. Those are corrupt extensions like ad-blockers, outdated browsers, and corrupt cache.
Update your browser if there’s a newer version available. Also, try disabling ad-blockers and other extensions, one by one. Keep checking your website simultaneously.
7. Fixing CDN server issue
To find out if your CDN server is down, you can check your CDNs status page, like Cloudflare System Status.
Alternatively, try these tools: CDNPlanet and Downdetector.
Even if the CDN is up, it could still be a CDN issue. Try disabling the CDN. If the error vanishes, then talk to the support team, asking them to fix the issue on their end.
![option to remove site from cloudflare](https://mllj2j8xvfl0.i.optimole.com/cb:jC7e.37109/w:550/h:239/q:eco/f:avif/https://themeisle.com/blog/wp-content/uploads/2021/06/remove-site-from-cloudflare.png)
8. Fixing DNS issue
Migrated to a new hosting provider or domain registrar recently? Then wait up to 24 hours for the DNS issue to be resolved automatically. And while you are at it, flush your DNS cache.
9. Fixing PHP timeout issues
You may think that increasing the PHP timeout limit will solve the issue. But hosting limits are not the problem here. The plugin or theme that demands more resources to process its PHP code is the main culprit.
The PHP limit exists to prevent abuse of your resources. Hence remove plugins and themes that threaten to exhaust your resources.
If the “502 bad gateway” WordPress error still persists
On rare occasions, when none of the solutions works, you need to hire professional help. Take a look at our guide on how to hire a WordPress developer.
Conclusion
Fixing some website errors can be annoying and time-consuming. This is why we believe that every WordPress website should take daily backups so that whenever you run into an error, you can simply restore your site back to normal.
This, of course, is not a permanent solution, but it does help you keep your website up and running, which allows you to investigate the problem at a more convenient time.
Do you have questions about the “502 bad gateway” WordPress error? Let us know in the comment section below!
Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!