If you are using WordPress, you might have been frustrated by the 502 Bad Gateway Error. And you are not the only one to be irritated it. Big names, like Google, are also among the affected ones.
While the issue might seem confusing, there are several easy ways to fix it. In fact, it takes only a few minutes to make everything OK. In this article, you will find 10 ways for solving the 502 Bad Gateway Error on WordPress. But before discussing them, let’s take a look at the details of the issue.
What is WordPress 502 Bad Gateway Error?
When you get into a website, your browser sends one or more requests to the web server. If there is no issue on the site, the requests are received and processed successfully. Now, the browser will be provided with all the requested information, including HTTP header and HTTP status code. The website will be loaded perfectly. However, if something goes wrong and the requests are not processed successfully, the web server sends back an invalid response. It is known as 502 bad Gateway Error.
What are the causes of 502 Bad Gateway Error?
There are many reasons behind the bad gateway issue. Some of the most common ones are:
- Bugs in the database of the website
- Unavailable or timed out server
- Issues with the reverse proxy server
- Issues in the PHP codes, which are generally caused by the third party software, including plugins and themes
- Server overloading due to the massive number of website visitors or a DDoS attack
- Firewall blocking the requests
How to Fix 502 Bad Gateway Error on Your WordPress WebsiteReload the Webpage
It might sound simple. But reloading the webpage is the most effective solutions for fixing the 502 issue. In fact, it is the very first thing that you should do when you encounter it. If you are using Google Chrome, press Ctrl + R to reload the page. In most of the cases, it fixes the issue of server overloading. As a result, the page is being displayed instantly without any issue.
Remove Problematic Plugins
If you are using problematic plugins, you are very likely to be affected with the 502 error. If there is a fault in the PHP code, your server will be affected with confusing scripts and queries. As a result, all of the sent requests are being canceled.
In other words, it will trigger the 502 Bad Gateway issue. To fix the problematic plugins, install FTP software, like FileZilla, in your PC. Then get into the WordPress root directory. Head to wp-content -> plugins. Change the name of the plugins folder to plugins_old to disable all of your plugins simultaneously. Now, reload your website.
You will find that the 502 error is gone. Now, change the name of the folder back to plugins and get into your WordPress admin. Then activate all of your plugins one by one and refresh your site. In this way, you can identify the problematic plugin. You should contact the developer for fixing the issue immediately.
Identify and Fix the Buggy Theme
Similar to the plugins, the bugs in the WordPress theme can create a massive problem with the server requests. To solve the issue, follow these steps:
- Sign in to your website via FTP. Then go to wp-content -> themes -> Your _Active_Theme.
- Right click on the activate theme and click on Download. You will use the downloaded copy as a backup.
- After downloading, right click on the active theme and click on Delete to remove it from WordPress root directory.
- Reload your website. If there is a white screen, your theme is affected by buggy codes. You need to contact your developer to fix them. In the meantime, you can use the default theme.
Bring Server Back Online
One of the major reasons behind the 502 Bad Gateway issue is the unresponsive server. If you are a typical user, it’s quite impossible for you to solve the server issue. However, if you have a basic idea and know how to find the origin of the error, you can report it to your developer quickly and effectively. To identify the source of the issue, you can go for the ping test.
Tracerouting is another great way of doing it. After detecting the origin, contact your developer as soon as possible to bring the server back online.
Even if you have taken a number of steps for fixing the issue, you might be still seeing the 502 Bad Gateway error. It can happen if the browser doesn’t load the website from the server. Instead, it might still be relying on the cache. In this case, you have to clear your browser cache. Go to Settings > Advanced. Find Clear Browsing Data feature. Go to Basic tab and find Cached Images and Files option. Select it and click on Clear Data. It will clear all the cache, along with your browsing data. Now, reload the website. You will see that the Bad Gateway error is gone.
The Bad Gateway issue often originates from the bug in the Content Delivery Network (CDN). So, you should try disabling it. If you are using a plugin, like CDN Enabler, it’s really easy to deactivate. If you are facing issues with accessing your WordPress dashboard, get into your site admin via FTP. Now, rename the folder cdn-enabler to cdn-enabler_old. Now, try to load your website. If you manage to get the access, CDN had been causing the issue. CDN uses reverse proxy technology, which inserts an intermediary between the website server and the browser. As you have disabled the CDN connection temporarily by renaming the folder, there is no chance for any middlemen getting in the way of origin server responding to the request. As a result, the 502 error is gone.
Fix DNS Issue
DNS issue, like the domain not dealing with the right IP, is another reason behind the WordPress 502 error. If you have just migrated your site, you should wait at least 24 hours (depending on the TTL value) for things to get OK automatically. However, if you are still seeing the 502 error, you can flush your local DNS cache using the following command in Command Prompt:
ipconfig / flushdns
If the process is done successfully, you will see “Successfully flushed the DNS Resolver Cache.” If it doesn’t work, you can try changing your DNS server. For instance, you can use a public DNS server, like Google’s.
Get Your Hosting Issue Fixed
One of the main reasons behind the 502 error is the issue with your web hosting. The server might be down due to the maintenance or some bugs. Also, there can be connectivity issues. Unfortunately, from a user perspective, you cannot fix the issue by yourself. You need to get in touch with the hosting company instantly. Contact the customer support and open a support ticket seeking their immediate attention.
Checking the error logs often work as a great solution. To enable logging, you have to add the following codes in wp-config.php file:
define( 'WP_DEBUG', true );define( 'WP_DEBUG_LOG', true );define( 'WP_DEBUG_DISPLAY', false );
In most of the cases, you will find the logs at /wp-content folder. If you are using Apache, you will find the logs here:
If you are using NGINX, head to the following location for getting the logs:
As you have the access to the log files, you can easily find and narrow down the errors. If a plugin is causing the Bad Gateway error, you can easily identify it by going through the logs.
Update Everything on WordPress
Updating everything on WordPress often solves the 502 error completely. So, you must check for regular updates for WordPress Core, themes and plugins. It will eliminate all the codes that can create a massive problem on your server. It will also solve all sorts of security issues.
502 Bad Gateway error is really irritating. But it is not the most difficult one to fix. By following all the ways that have been mentioned, you can easily get rid of it and make your website fully functional. Have you been ever frustrated with the 502 error? How did you fix it? What is your experience? Share your thoughts with us through our social media channels.
Check out these top 3 WordPress hosting services: