WordPress at certain times throws the 502 Bad Gateway Error. It can be frustrating when you’re getting an error message while trying to access something important or urgent.

There are several ways to solve this error, which takes a few minutes. In this article, find top 10 ways to fix the 502 Bad Gateway Error in WordPress.

Why 502 Bad Gateway Error Occurs?

When you visit a website by typing in the URL address, the browser sends requests to the web server. The requests are received and processed on the server. The required files are then send over to the browser to display to the end user. But if the server fails at something, it will send back and invalid response, called the 502 Bad Gateway Error.

Here are some of the reasons why that may happen:
  • There was a bug in the website’s database.
  • The server timed out or was unavailable to handle the request
  • There was issues with the reverse proxy server
  • PHP codes were incorrect, probably because of a third-party software or plugin
  • The server is overloaded due to increase in web traffic or DDoS attack
  • A firewall blocked the connection
Fixing the 502 Bad Gateway Error

Here are ten ways to fix the bad gateway error. Try them one by one.

Reload the Website

The first and simplest solution to try is to reload the page. If nothing happens, wait for a few minutes and retry. Sometimes the error resolves automatically. But when the problem persists, try the following solutions:

Remove Unverified Plugins

The next step is to remove any plugins that is created by unreliable publishers. These plugins are created in PHP as well. So they may interfere with the scrips and queries, which may result in requests being canceled.

Go into the Plugin manager and disable all the plugins that you find suspicious or not necessary. Then, check if the problem is fixed.

Remove Buggy Themes

The theme can cause the error as well. So you need to remove buggy themes. You can use the themes manager or FTP for this purpose.

If using FTP, here are the steps to follow:
  • Connect to your server using FTP

  • Navigate into wp-content >> themes >> Your_Active_Theme
  • Right-click on the theme and click on “Download.” Save this copy as a backup

  • Then right-click on the theme once again and click on “Delete
Reload the website to check if the problem is fixed. If so, download and use another theme. If not, restore the theme and use the other solutions.

Clear Cache

Cache can sometimes interfere with server requests. Or, the problem might have already been fixed, but because of the Cache codes, you continue to see the 502 Bad Gateway error.

Go to your browser settings and manually clear the cache. Then login to WordPress dashboard, navigate into Settings >> Advanced. Open the “Clear Browsing Data” feature. Find the Basic tab and then Cached Images and Files option. Finally, click on Clear Data.

Restart the Server

You may want to restart your server to fix this error. At times, the server just stops abruptly. So contact your development team or hosting provider and ask them to restart the server.

Disable CDN

If you’re using Content Delivery Networks, which can speed up your website, you may disable them and recheck.

In case you’re facing trouble with opening your website in the browser, connect via FTP. Rename the CDN folder to something else, like cdn-enabler to cdn-enabler_old.

If you manage to open the website, then CDN is the culprit. So take necessary measures.

Identify and Fix DNS Problems

The problem can be with DNS as well. In such cases, the domain isn’t connecting to the right IP address. If you recently migrated your website, wait for 24 hours for things to normalize. But if you persistently get this error, flush your local DNS cache. Use this command for this purpose:

ipconfig / flushdns
Recheck to see if the problem is fixed.

Fix Your Hosting

The problem may lie in hosting as well. Perhaps the server is down due to maintenance or bugs. So contact your hosting provider to check if that’s the case.

Check Logs

Logs is a great place to look for errors associated with your WordPress website. To enable logging, you need to add the following codes to the wp-config.php file:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
Then you can find the error logs at “/var/log/apache2/error.log” if you’re using Apache. You can also find the logs at “/wp-content.”

For users on NGINX, navigate into this location - “/var/log/nginx/error.log”

Check the logs to see if there’s something that might be interrupting connection to the server. Then, take necessary measures.

Update WordPress and Others

The final thing you should try is update the WordPress platform. This often solves the 502 error. So check if there’s any available update for WordPress Core, the theme, or the plugins. Update everything and check if the error is resolved.

So those are some of the ways to fix 502 Bad Gateway error. If problem persists, seek assistance from the hosting provider.
First release
Last update
0.00 star(s) 0 ratings

More resources from kumkumsharma