One of the most frustrating aspects of running a website is having to fix an error when you do not know why it is happening. Some problems, such as 502 Bad Gateway, have many possible causes. This means that you may have to try several solutions before landing on the correct one.
If you understand a little about the error in question, on the other hand, you will have an advantage when it comes to solving it. In this article, we’ll talk about what the 502 error is and what can cause it. Then, we will teach you how to solve the problem. Let’s go to work!
What is the 502 Bad Gateway Error and why it happens
When you visit a website, your browser sends one or more requests to the server that hosts the site. If everything works correctly, that server will send the information requested by your browser and the website will be loaded. On the other hand, 502 Bad Gateway occurs when a server returns an ‘invalid’ response.
This may mean that the connection has timed out or may be the result of several other problems.
So far, this may sound simple. However, the connection between your browser and most websites is not as direct as it used to be. For example, your browser request can be routed through a proxy server before going to the host in question, so it can be difficult to determine where the problem is. Many websites also use multiple servers, which complicates things even more, since any of them could be the cause of the 502 error.
All this means that there are some potential causes for this particular error code. It could be the result of:
- Errors in your database
- A server that has exceeded the wait time that is currently not available or that simply does not work as expected.
- A problem with your reverse proxy server.
- Defective PHP scripts, courtesy of one of your add-ons or themes.
The good news is that if the problem is with the server, you may not need to take any action. In these cases, your hosting provider will usually jump to the rescue quickly (since customers tend not to appreciate downtime).
With this in mind, we will focus on what to do if the 502 bad gateway error does not disappear quickly. Most websites cannot afford to be inactive for hours, after all, so if this error persists, it is time to start solving problems on your part.
502 bad gateway fix on WordPress
Before going into troubleshooting mode, there is a quick test that you can run to determine if your server is responding as it should. You can try running a traceroute, to see if your server is accessible in the first place. If so, then the problem is probably at your end. Otherwise, you may want to contact your web hosting provider.
You should also try to reset your router and verify your Domain Name System (DNS) configuration. These are basic solutions that can sometimes make the 502 error disappear, and are quite easy to solve on your own. If you find that no solution solves the problem, however, you can use the following methods to solve the 502 error.
1. Clear your browser cache
502 bad gateway may appear when you try to access your website, even if the underlying problem has been resolved. This happens if your browser trusts your cache, instead of loading the latest version of your site from the server.
Simply reloading the site a few times can do the trick. If you do not, and you are using Windows, you can try using the CTRL + F5 command. This forces your browser to reload the website and empty its cache, and it works on most browsers (including Chrome and Firefox). Instead, OS X users will need to use the CMD + CTRL + R command to have Safari achieve the same result.
If all of the above fails, you should proceed to empty your browser’s cache manually. Chrome users can do this by navigating to the Settings> Advanced menu and locating the Clear Browsing Data option:
Look for the Cached images and images option on the Basic tab and click Clear data after selecting it. Note that this menu will also delete your browsing history, if you do not disable that configuration 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 cleared the cache, try reloading your website one more time. If the error persists, it’s time to get serious.
2. Temporarily disable your content delivery network (CDN)
Previously, we mentioned that requests from your browser would 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 website’s server.
Some services, such as Content Delivery Networks (CDN), rely on reverse proxy technology to route incoming traffic as efficiently as possible. However, sometimes this additional layer can create problems when you try to connect to the source server of a website. When that happens, your visitors (and you) may encounter the dreaded Gateway 502 error.
Fortunately, it is fairly easy to verify 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 is properly loaded without it. The process of disabling your CDN will vary depending on the service you are using, but it is simple.
For example, Cloudflare users only have to navigate to the Overview tab on their dashboard. Inside, you will find a list of properties that are running the service. Then you should look for the Large Pause button in the Pause the website section and click on it:
Now, when you try to access your website, your home server will respond to the request without intermediaries on the way. If 502 bad gateway is gone, then your CDN was probably the source of the problem. In some cases, you only have to wait a few hours before re-enabling the service. Of course, be sure to check and make sure the error still disappears.
If you are using another CDN, you should consult your documentation for instructions on how to temporarily disable the service. However, if your CDN is not the problem, there is one more solution you can try.
3. Test your WordPress themes and add-ons
So far, we have talked about three possible causes of 502 bad gateway: your server, your browser and the services of intermediaries, such as CDNs. That only leaves one option if you’re sure the problem is on your side, and that’s your WordPress website. More specifically, one of your add-ons or themes may be trying to execute a script that your server cannot load correctly. This may result in an invalid response when your browser sends a request, triggering the 502 bad gateway.
You can only have one theme active at a time, so you can simply disable the current one and temporarily change to a default WordPress theme, to see if that solves the error. On the other hand, finding out if a plugin is causing problems may take more time, depending on how many of them are currently active.
As you do not have access to your board at this time due to the error, you must disable its add-ons and themes manually. Know that this process does not involve removing the add-ons and themes, and reactivating them takes only a moment. Therefore, the functionality of your website should not be affected. Even so, you should have a recent backup list just in case.
Then, open the FTP client of your choice. We are great fans of FileZilla so that we will use it as our example.
Log in to your website via FTP and go to the folder public_html> wp-content> add-ons. There should be a folder for each of the add-ons installed inside, even those that are not active:
If you right-click on any of those folders, you will see several options, including one labelled Rename. Click on that now and change the name of the folder to something similar to disabled.pluginname:
When you access your website now, WordPress will not be able to find that add-on so that it will be loaded without it. If the add-on you just turned off caused the 502 error, your website should load correctly. Just to be sure, remember to use the CTRL + F5 command (or the OS X equivalent) to force your browser to remove its cache before reloading the site.
To avoid confusion, you must fix one plugin at a time. Change the name of a folder, try to reload your website and see if it still shows 502 bad gateway. If so, restore the original name of the folder. Repeat this process with each folder until you find the one that is causing the error or until you have tested each add-on.
You can use the same process to test your active topic, which will force WordPress to use one of its default themes.
If one of your add-ons or themes is causing the 502 bad gateway, you can obliterate it and look for a replacement. If it’s outdated, you can also try updating it, to see if that solves the problem. In some cases, the problematic script will be re-shot quickly, so you can always resume using that add-on or theme later.
WordPress problem solving is often easier than you think. Even problems that have many possible causes, such as 502 bad gateway, are well understood and documented. You may have to try several solutions before you land on one that works, but the problem-solving process should not take too long if you follow the correct instructions.
If you encounter the 502 bad gateway error on your website and it does not disappear after a few minutes, it is likely that the problem is at its end. In that case, this is what you want to try:
- Clear the cache of your browser.
- Temporarily disable your CDN.
- Test your WordPress themes and add-ons.
Have you ever encountered the error 502 bad gateway on one of your WordPress websites? Share your experiences with us in the comments section below!
Searches related to How to Fix 502 Bad Gateway Error
- 502 bad gateway nginx fix
- 502 bad gateway wordpress
- bad gateway 502
- error 502 bad gateway cloudflare
- 502 bad gateway nginx wordpress
- 502 bad gateway php
- 504 bad gateway
- 502 bad gateway aws