If an error is making your WordPress unusable, of course, that is a serious problem. Because the consequences will be lost revenue, poor SEO rankings, and a lot of unreasonable stress. So, one of the troublesome errors in WordPress is the 502 bad gateway error. It is a very annoying one because there might be several reasons behind it making the troubleshoot quite difficult.
But you don’t have to worry a bit. We are here to help you with several solutions. All of them are tried and tested by us. So, once you finished reading this article the 502 bad gateway error will be gone. keep reading!
What is a 502 Bad Gateway Error?
Before jumping into the solutions, let’s learn something about the error. As you might know already, hosting your WordPress site involves several servers. The most basic setup might involve four to five servers which are named as below.
- An application server that processes your PHP code and any other dynamic content on your site
- A database server where your databases are
- Reverse proxy server e.g. Nginx and Apache that controls which HTTP requests go where
- The web server that stores all of your static files such as images, CSS and JavaScript
- A CDN (optional performance server)
So, once you enter your site URL into your browser and hit ENTER, the browser will send some HTTP requests to the reverse proxy server. After that, the reverse proxy server then directs the requests to the respective servers. As an example, requests for the data stored in your database will be routed to the database server, requests that require PHP are processed by the application server and requests for static files are routed to the webserver.
Then all servers send back data to the reverse proxy server. Then the reverse proxy server sends the data to your browser. So, the website loads. Just as simple as that!
Furthermore if one of those servers sends an invalid response to the reverse proxy server, the website won’t load in your browser as you expected. And the reverse proxy server will display you the 502 bad gateway error.
Other forms of the error
The 502 gateway error can take other forms like,
- Error 502
- A 502 Bad Gateway NGINX
- The 502 Proxy Error
- 502 Service Temporarily Overloaded
- HTTP Error 502 Bad Gateway
- 502. That’s an error. The server encountered a temporary error and could not complete your request. Please try again in 30 seconds.
What causes a 502 Bad Gateway Error?
As you already know the error usually happens on the server-side. But it can happen due to some problems in your end too. The following are several reasons why you are experiencing the 502 bad gateway error.
- Your upstream server may be overloaded due to a traffic spike
- An offline server
- Server misconfigurations that might aside due to many reasons such as human error especially when your host move servers
- Issues with your content delivery network (CDN)
- Misbehaving browser cache
- DNS problems
- Incorrect PHP code due to a problematic plugin or theme
According to the above list, there are several possibilities. Number of possibilities, number of solutions.
With keeping that in mind, let’s get to work.
How to fix a 502 Bad Gateway Error in WordPress
Even though the error is somewhat annoying, fixing is easy. The only thing you need to have is a little bit of patience.
#1: Refresh/Reload your site
As the error usually happens on the server-side (the chance is more if you’re on shared hosting), a rise in traffic may exhaust your server causing the error. Or else your servers might be acting up or offline for some reason.
Usually hosting providers will resolve the problem immediately. Because website owners don’t like downtime and they lose revenue when the sites are offline.
So, before jumping into any conclusion just refresh your WordPress site several times. Or else you can try login using a different browser or a different device. And you can use a tool like isup.me to test your site and to confirm the problem is not on the server-side. If any of this didn’t help you, let’s move on to the next solution.
#2 : Clear your browser cache
If a soft refresh didn’t work for you, you can try a hard refresh on your browser. Its CTRL + F5 for Windows systems and CMD + CTRL + R for OS X systems. If that didn’t help either, you can try clearing your browser cache by using the tips in how to clear WordPress cache. And look for the error after deleting the cache. If it is still there annoying you, just stay with us.
#3: Temporarily disable your CDN
Do you use a content delivery network? Like CloudFlare, KeyCDN, or another CDN for WordPress? They often route your website traffic to their servers to give you a better site performance and security.
But a problem in their servers might affect you giving rise to the 502 bad gateway error. Or else if you incorrectly configure the CDN, that might also give the error.
To find out whether the culprit is your CDN, pause it, and refresh your site. This will load the site directly from your host servers.
And the error no longer appears after pausing your CDN, keep it paused and contact their support department. Often they will fix the problem shortly, but you may have to do without the CDN for a short period. Please keep in mind that every CDN has a different interface and pausing the service is also different. So you have to check it with your CDN.
#4 : DNS problems
DNS stands for Domain Name System. It’s the process of how domain names match their respective IP addresses. You may experience the 502 gateway error if there is something wrong with DNS settings.
If you are seeing the error after migrating to a new host recently, wait till the DNS changes are propagated. It can take up to 48 hours in some cases. If it takes more than that you can contact your host fr
Now you may be wondering how migration causes the error. That’s because migration includes re-configuring your DNS servers. Another option is you can try to flush your local DNS cache. If you are a Windows user open your command prompt (cmd.exe) and run the following command: ipconfig /flushdns. And if you are a Mac OS X user, run dscacheutil -flushcache in the command terminal.
#5: Check your theme and plugins
Still, suffering?? Maybe the issue lies in your plugins or theme. If there is a firing script in your theme or one of your plugins that don’t play well with your server, that might be the culprit.
So, the server kills the script leading to the 502 bad gateway error. Let’s start with plugins first.
#6: Troubleshooting Plugins
Most probably the error will prevent you from login into your WordPress admin dashboard. Then you have to log in to your WordPress root directory using an FTP app like Filezilla or File Manager in cPanel.
Now navigate to wp-content and locate the plugins folder. Then rename the plugin folder to something like plugins.old. This will deactivate all your plugins at once while preserving the data.
Then refresh your site and look for the error. If the error is gone, one of the plugins is the troublemaker. Now you have to find the problem causing plugin. Before that, rename plugins.old folder back to plugins and login to your WordPress admin dashboard.
Then activate plugins one at a time while reloading your site after each activation. Repeat this till you find the culprit plugin. And be careful that the troublemaker plugin will recreate the 502 bad gateway error upon activation and it might lock you in the admin area. Finally, deactivate or eliminate the plugin via FTP or File Manager. Or else you can get an alternative or contact the developer for further assistance.
#7 : Troubleshooting your active theme
If any of the above solutions didn’t help and the error started after updating your site, you have to troubleshoot your WordPress theme. First login to your WordPress root directory via FTP or File Manager. And then go to wp-content > themes and find your active theme.
Now rename the active theme folder to something like total.old. So the active theme will be deactivated and the default WordPress theme will be activated.
Then reload the site and see whether the error is still there or not. If the error is gone, contact your theme developer for further assistance. And also you can consider investing in a professionally built theme like our very own
If it is still there your theme is fine and you have to rename the theme folder back to the previous name.
If none of the above solutions didn’t work for you. We strongly recommend you to contact your host and get professional advice. Furthermore, consider investing your valuable money in a top-level host to avoid this error because of lower server resources in shared hosting plans.