How to Fix 502 Bad Gateway Error in WordPress

Jeniffer| 2018-03-06 Tutorials, WordPress Comments( 1 )

For website owners, it is frustrating that they have to cope with error on your websites but they really do not know why it is happening. Many issues such as 502 Bad Gateway Error have various potential causes. If you are not sure which causes the 502 error, then you have to test more than one solution to fix it till you find the right one. 

Even though you are not sure the real cause of the issue, you still have to know the error you are facing. Once it is happening in front of you, you will not have a headache. In this guide, we are going to talks about discuss the 502 error in WordPress and the methods to cope with it. Let’s get started!

What’s the 502 Bad Gateway Error?

When you are browsing a website, browser will send many requests as you need to the server hosting the site. Normally, if there is nothing going wrong, then the server will send the information you just asked back, and then the site will load it. However, if the server does not send the information asked back, but gives the message of “invalid”, it means the connection timed out, or there are some other problems. 

Up till now, you may think it the error sounds simple. If that, you are wrong. In fact, the connection between the websites and your browser is not straightforward as usual. For instance, your request via your browser could be routed though the proxy server before it makes the way to the server hosting the site, thus it could be difficult in pinpointing the exact place that the real issue takes place. 

Even worse, many website may use more than one server, and it can make the thing more complicated because you have to locate which server goes wrong to lead to 502 error. 

All these indicate that there could be multiple potential causes for the 502 error. According to our experience, we conclude them as following:

  • Something is wrong in your DB;
  • The server hosting the website is just timed out and unavailable now, or it does not work as planned;
  • Your server proxy server goes wrong.
  • One of your themes or plugins includes faulty PHP scripts.

Fortunately, if you can define the issue is located within the server, it may be much easier, because you just need to contact your provider and explain your condition. Then, you can sit back for good news. 

Due to this situation, our discussion will just focus on the solutions to deal with the situation that the 502 error does not disappear on its own quickly. We know that most websites cannot afford long-term downtime (lasting for even hours). So, if the error is still there, you should take action to troubleshoot on your end. 

How to Fix the 502 Bad Gateway Error in WordPress

Before you start to troubleshot mode, you can run a quick test to determine if the server is working as normal. Firstly, you can run a traceroute to check if the server is available. If you the test is smooth, then the real issue is most likely to locate on your own end. If the traceroute test shows your server is not reachable, then you need to contact your WordPress hosting provider. 

Besides, you can reset your routers and check your DNS settings as well. They both are the basic factors sometimes making the 502 error disappear. Also, these are simple enough to make by your own. If these basic methods cannot fix the 502 error, you can follow the solutions below to have a try.

1. Clear Your Browser Cache

The first case is that after all underlying problems have been fixed, but when you attempt to access the website, you are still blocked out of your website and the 502 error still appears. If your browser relies on its cache, instead of loading the latest website version from remote server, then the case will occur.

In this case, it is simple to solve. You just need to reload the website sever times and then do the trick. However, if you still have the 502 error message on screen and you are just utilizing Windows, then you can use CTRL +F5 command to have a try. It will make your browser reload the site with the latest version and empty browser cache. This method can work across major browsers currently including Firefox and Chrome. 

Well, for OS X, you will need to try the command of CMD+CTRL+F5 to make Safari have the same result. 

Unfortunately, if all these are failed, you have to get started to manually empty the browser cache. Supposed that you are using Chrome, then you can do this by going to “Settings” >> “Advanced” and find the option “Clear Browsing Data”. 

Locate the option “Cached Images and Files” under “Basic” tab, and then press “Clear Data” once you selected it. One thing you need to keep in mind is that if you do not disable the setting before you press “Clear Data” button, performing this order will delete all browsing history.

For Firefox, Internet Explorer, Safari and almost other browsers can all perform the same process to deal with the situation above. After clearing the browser cache, you can try to reload thee website again. In most case, these methods are good to fix the error. If the problem is still there, then you should be more serious. 

2. Temporarily Disable Your CDN

In previous part, we have mentioned that your request may be routed through the reverse proxy server. That is to say, you are utilizing the proxy server to place an intermediary between your server and audience’s browsers.

Now there are some services like CDN, routing incoming traffic by relying on the reverse proxy for better more efficiency. Nevertheless, the additional layer sometimes may cause troubles as you are attempting to connect to the origin server of your website. Once it occurs on your site, you and your audience will experience the terrible 502 bad gateway error. 

You can check out whether your CDN is the cause of the issue. For this purpose, you just need to temporarily disable your CDN. After that, you can test if your site is loading right without the service. According to different CDN services you are applying to your site, the disabling process is different, but fortunately it is often very easy.

In this post we are to take CloudFlare as our instance to show you how to temporarily disable it. You just need to navigate to “Overview” tab in the dashboard in which you can find a property list to rung the CloudFlare CDN. Now, you can proceed to find a bog “Pause” button in the section of “Pause Website”, and then press the button.

After disabling your CDN service, your site will directly load from your origin server to repose your requests when you attempt to access it. If your site goes correctly, then you can understand the issue must be located in your CDN service. In the situation, you have to wait for hours to re-enable the CDN service. Remember to check again that if the 502 error is gone after the re-enabling.

Sometimes, it does work and you still know the problem is not in the service. Then, we have one more method to have a try to do the trick.

3. Test Your WordPress Plugins and Themes

Looking at the discussion above, we have talked about 3 potential causes of the 502 error, which are your origin server, your intermediary services like CDN, and your browser. In this part, we are to focus on the last one, your WordPress website. 

To be specific, there may by even tiny error within your WordPress themes or plugins or one of them is trying to execute a script which your origin server cannot load correctly. In this case, it can lead to an invalid response, as your browser sends requests, to trigger the 502 error. 

Each time you can only activate one WordPress theme on site, thus it is simple to deactivate it currently using and then switch to the default theme temporarily. Now you can try to access your site again to check if the problem is solved. Differently, you can activate multiple plugins on your site, meaning you need to test as many times as the plugins you are suing on your site, so as to figure out the wrong one. 

Besides, if you are blocked out of WordPress dashboard because of the error, then you have to disable these plugins and theme manually. Note that the process does not include deleting these plugins and theme, and also to reactivate them only needs a moment. Therefore, the functionality on your site will not be impacted. However, for the sake of safety, you also need to take a backup of your site.

We have ever talked about the method of disabling WordPress plugins or themes. Here we will still use FileZilla to do this. Open the FTP client you selected and log into your site via FTP client and proceed to find “public_html” >> “wp-content” >> “plugin folder”. You can find the folders there for each plugin you installed on site, no matter whether it is active or not.

Right click on a plugin folder, you can get different options can be applied to the plugin, and one of them is “Rename”. Choose that option and then chance the folder name to others such as “disabled.thepluginname”.

Now, if you access your site again, you will not find these plugins just disabled on site. It means your site will load without these plugins. In other words, if it is these plugins that case the 502 error, then you can browse it as normally now. Also, you have to remember to apply the command CTRL+F5 to make you’re the browser delete all cache before it reloads. 

In order to avoid unnecessary confusion, we commend to disable your plugins one by one to test which exactly cause the issue. Besides, you need to remember to restore the plugins just have excluded to be the cause of the issue: just need to change the plugin folder’s name back to the original one. For WordPress theme, you can do the same process to test it. 

Once you find the right plugin or theme to cause the 502 error, just delete it all and find another replacement. Or if the plugins or theme is just outdated, then you can try to update it to see whether it can work again. 


WordPress make website creation much easier and to troubleshoot it errors is often easier than image. Even though some errors have multiple potential causes, you just need to understand them and solve it according to those potential causes one by one. Always remember that you should take copies or backups of your website before you make any change or start any step on your site. 

If you have ever experienced the 502 error on your WordPress website, please be generous to share your methods with use in our comment part below! 

Tagged with:

We hope webmasters to share and promote the good articles ,Please click herecontribute

You need to log in to commentLogin|Register

All Comments(1)

2018-05-29 09:47
In my experience, I have to say that the best and easiest way is to have decent hosting. This is because a good hosting provider will enable me to check server error logs on my WordPress site. It is a valid point which should deserve a high attention. Certainly, you do give some clues when there is the need to fix 502 errors.