One of the most frustrating aspects of running a website is having to resolve an error when you do not know why this is happening. Some problems, such as the incorrect gateway 502 error, have many potential causes. This means that you may have to try several solutions before landing on the right one.

If you understand a little bit about the error in question, on the other hand, you will have a length of time when it comes to fixing it. In this article, we will talk about what the 502 error is and what can cause it. Then we will teach you how to solve the problem. Let's get to work!

What is the error 502 Bad Gateway is (and why it occurs)

How To Fix The 502 Bad Gateway Error In Wordpress The error 502 bad gateway appears from time to time, which often means that there is a problem with your server.

When you visit a website, your browser sends one or more requests to the server that hosts the site. If everything works correctly, this server will return the information requested by your browser and the website will be loaded. On the other hand, the incorrect gateway error 502 occurs when a server returns an "invalid" response. This may mean that the connection has expired or may be the result of several other problems.

Up to now, this may seem simple. However, the connection between your browser and most websites is not as simple as it used to be. For example, your browser's request can be routed through a proxy server before heading to the host in question, so it can be difficult to locate the problem. A lot of websites also use multiple servers, which complicates things even more since one of them could be the cause of the 502 error.

All of this means that there are some potential causes for this particular error code. This could be the result of:

Errors in your database .
A server whose timeout is exceeded, currently unavailable, or not working as expected.
A problem with your reverse proxy server.
Faulty PHP scripts courtesy of any of your plugins or themes.

The good news is that if the problem is with the server, you may not have any action to take. In these cases, your hosting provider will quickly go to the rescue quickly (since customers tend not to appreciate the downtime).

With this in mind, we will focus on what to do if the wrong 502 gateway error does not go away by itself quickly. After all, most websites can not afford to be idle for hours, so if this error persists, it's time to start troubleshooting on your side.

How To Fix Bad 502 Gateway Error In WordPress (3 Potential Solutions)

Before you switch to troubleshooting mode, you can run a quick test to determine if your server is responding as expected. You can try to run a traceroute to see if your server is reachable in the first place. If that's the case, then the problem is probably on your side. Otherwise, you may want to get in touch with your hosting provider.

You should also try to reset your router, and check your Domain Name System (DNS) settings . These are basic fixes that can sometimes make the 502 error go away, and they are pretty easy to solve on your own. If you find that no solution solves the problem, however, you can use the following methods to resolve the 502 error.

1. Clear your browser cache

The 502 error may appear when you try to access your website even though the underlying problem has been solved. This happens if your browser uses its cache rather than loading the latest version of your site from the server.

Simply reloading the site multiple times can often do the trick. If this is not the case, and you are using Windows, you can try using the CTRL + F5 command. This forces your browser to reload the website and clear its cache, and it works on most browsers (including Chrome and Firefox). OS X users will need to use the CMD + CTRL + R command for Safari to achieve the same result.

If all of the above fails, you must manually clear your browser cache. Chrome users can do this by going to the Settings> Advanced menu and selecting the Clear Browsing Data option:

How To Fix The 502 Bad Gateway Error In Wordpress

Look for the Cached images and files option on the General tab, and then click Clear data after selecting it. Keep in mind that this menu will also delete your browsing history if you do not clear this setting before clicking the Clear Data button.

This same process can also be completed using Firefox Safari Internet Explorer and almost any other browser. When you have flushed the cache, try reloading your website once again. If the error persists, it's time to become serious.

2. Temporarily disable your content distribution network (CDN)

Earlier, we mentioned that requests from your browser will sometimes be routed through a reverse proxy server. In other words, the use of a proxy server places an intermediary between the user's browser and the site's server.

Some services, such as Content Delivery Networks (CDN) rely on reverse proxy technology to route incoming traffic as efficiently as possible. However, this extra layer can sometimes create problems when you try to connect to the origin server of a Web site. When this happens, your visitors (and you) could run through the terrible mistake 502 wrong gateway.

Fortunately, it's pretty easy to check and see if your CDN is causing this problem. All you have to do is temporarily disable the service and then test if your website loads correctly without it. The process of disabling your CDN varies depending on the service you use, but it's usually simple.

For example, users of Cloudflare simply need to access the Presentation tab in their dashboard. Inside, you will find a list of properties that run the service. Then you will have to look for the big Pause button in the Pause section of the website and click on it:

How To Fix The 502 Bad Gateway Error In Wordpress

From now on, when you try to access your website, its original server will respond to the request without intermediaries interfering with you. If the error 502 disappeared, your CDN was probably the source of the problem. In most cases, you will have to wait a few hours before reactivating the service. Of course, be sure to check and make sure that the error is still gone.

If you are using another CDN, you should consult its documentation to find out how to temporarily disable the service. However, if your CDN turns out not to be the problem, there is another solution that you can try.

3. Test your WordPress themes and plugins

Up to now, we have talked about three potential causes behind the 502 error: your server, your browser and the intermediary services such as CDNs. This leaves only one option if you are sure the problem is on your side, and that is your WordPress site. Specifically, one of your plugins or themes might try to run a script that your server can not load properly. This may result in an invalid response when your browser sends a request, triggering error 502.

You can only have one active theme at a time, so you can simply disable your current and temporarily switch to a default WordPress theme, to see if that resolves the error. On the other hand, determine if a plugin causes problems may take longer, depending on the number of them that are currently active.

As you do not have access to your dashboard yet thanks to the error, you will have to disable your plugins and your themes manually. Keep in mind that this process does not involve removing plugins and themes, and reactivating them only takes a few moments. The functionality of your website should not be affected. Even so, you should have a recent backup ready just in case.

Then open the FTP client of your choice. We are big fans of FileZilla so let's use it as an example. Log in to your website via FTP and navigate to the public_html> wp-content> plugins folder. There should be a folder for each of your plugins installed inside – even those that are not active:

How To Fix The 502 Bad Gateway Error In Wordpress

If you right-click on one of these folders, you will see several options, one of which is labeled Rename. Click on this now, and change the folder name to something like disabled.pluginname:

How To Fix The 502 Bad Gateway Error In Wordpress

When you access your website now, WordPress will not be able to find this plugin, so it will load without it. If the plugin you just turned off was causing the 502 error, your website should load correctly. To be sure, do not forget to use the CTRL + F5 (or OS X equivalent) command to force your browser to clear its cache before reloading the site.

To avoid confusion, you must troubleshoot one plug-in at a time. Change the name of a folder, try reloading your website, and see if it still displays the 502 error. If that is the case, restore the original name folder. Repeat this process with each folder until you find the one that is causing the error, or until you have tested each plugin. You can use the same process to test your active theme, which will force WordPress to use one of its default themes.

If any of your plugins or themes cause the 502 error, you can delete it completely and look for another one. If it is out of date, you can also try to update it to see if it solves the problem. In some cases, the problem script will be corrected quickly, so you can continue to use this plugin or theme later.


Troubleshooting WordPress Errors is often easier than you think. Even problems that have many potential causes, such as the bad 502 gateway error, are well understood and documented. You may have to try several solutions before you get started on a solution that works, but the troubleshooting process should not take too long if you follow the correct instructions.

If you encounter the 502 bad gateway error on your website and that it does not go away after a few minutes, there is a good chance the problem is on your side. In this case, here's what you'll want to try:

Clear your browser cache
Temporarily disable your CDN.
Test your WordPress themes and plugins.

Have you ever met the error 502 bad gateway on any of your WordPress sites? Share your experiences with us in the comments section below!

Article thumbnail image by windwheel /

The article How to fix the error 502 Bad Gateway in WordPress first appeared on Elegant Themes Blog .


Please enter your comment!
Please enter your name here