How to Fix the 502 Bad Gateway Error in WordPress?

How to Fix the 502 Bad Gateway Error in WordPress?

Have you ever seen a 502 Bad Gateway Error on your WordPress site?

Do you want to fix this annoying and frustrating error from your WordPress site?

If yes, we will help you get rid of this error. This error caused by a lot of different things that’s why it takes time to fix.

502 Bad Gateway Error

What is 502 Bad Gateway Error?

502 Bad Gateway Error, generally receives an HTTP error code when it sends one or more requests to your browser WordPress hosting server, then it sends back an invalid response. That means may be the connection timeout or any other issue. Usually, the server finds information and send back to your browser with the status code.

HTTP status codes that begin with digit 5(5xxx), which relates to an errors that occur when there’s a miscommunication between several servers. Some of 5(5xxx) series error is 500 Internal Server Error504 Gateway Timeout.

Your website is using multiple servers, which results in complication, and it causes 502 Bad Gateway Error. The most popular server setup that supports WordPress site includes some servers:

1. Database Server: which runs your WordPress database.

2. Application Server: that executes login, PHP code and other dynamic content of your WordPress site.

3. Reversed proxy server: which runs software, such as Nginx, Apache, etc.

4. Web Server: which provides services to your website files.

What causes 502 Bad Gateway Error?

The most common reason for 502 Bad Gateway Error, when your request takes a long time from server to respond. Maybe this delay is temporary due to the high traffic. Some potential reason for this particular error code. It could be the result of:

1. Error with your database.

2. There is a problem with your reverse proxy server.

3. A server that is timed out, currently unavailable or not working well.

4. Maybe a problem with your reverse proxy.

5. Fault in Php scripts of one of your plugins or theme.

6. Server Misconfiguration.

Different ‘502 Bad Gateway Error’ Variations

Due to various browsers, the 502 error represents in different ways.

  • “502 Bad Gateway”
  • “HTTP Error 502 – Bad Gateway”
  • “502 Service Temporarily Overloaded”
  • “Error 502”
  • “502 Proxy Error”
  • “HTTP 502”
  • “Bad Gateway: The proxy server received an invalid response from an upstream server”
  • “Temporary Error (502)”
  • “502 Server Error: The server encountered a temporary error and could not complete your request”
  • “A blank white screen”

Methods to fix 502 Bad Gateway Error in WordPress

While the 502 Bad Gateway Error is usually an issue with the server/network, it can also be client-side. Therefore, we will resolve the error on the client-side as well as server-side.

Method 1) Reload your WordPress Site

Before you attempt anything else, wait a minute or so and reload the page. Maybe the problem automatically disappears.

Sometimes server took a long time to respond due to traffic or other reason. Maybe your host or server is overloaded, but after some time, it loads the site back. If this doesn’t resolve the problem, close all the active sessions in your browser, and restart your site in a new tab.

Method 2) Clear Browser Cache

If the error not resolved, then there is a chance that a specific cached element causes it.

The browser loads your website from the cache, rather than loading the latest version of your site from the server. To empty your browser cache manually, use a key combination ctrl+shift+del, then click on the Clear data button from the pop-up screen.

Clear Cache And Cookies

You can also use a different browser to resolve this issue. It also tells you whether the error is showing due to browser related issues.

Method 3) Check Error Logs

If 502 Bad Gateway Error occurs after some changes or updates, then it is possible that the mistake is on the website itself. The best way is to check your error log for any hints.

To enable error logs in WordPress, you have to add the following line of code in the wp-config.php file:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

All the log entries appear in the wp-contents/debug.log file.

Method 4) Flush DNS

The 502 Bad Gateway error can also occur due to DNS issue, such as incorrect IP address values. Make sure your DNS settings are working fine and configured accurately. In such case, to flush DNS follow the below steps:

  • Flush DNS in windows
  • Use Window+R key combination to open the Run Dialog Box. Type cmd commands and click on ok button.

    Run Command In Bad Gateway

    To clear DNS to enter the ipconfig /flushdns command in your command prompt and press enter. Wait for a minute you’ll see a confirmation message that Successfully flushed the DNS resolver cache.

  • Flush DNS on Ubuntu Linux
  • To flush DNS in Linux open your terminal and execute the sudo service network-manager restart command.

  • Flush DNS Mac users
  • To flush DNS for Mac users, enter the dscacheutil -flushcache command in the terminal.

    Method 5) Temporarily Disable Your CDN

    CDN (Content Delivery Network) is a service that serves files to boosts site performance on behalf of the WordPress site. It relies on reverse proxy technology to effectively route incoming traffic. A proxy server acts as an intermediate between the user’s browser and the server.

    If you are working with the CDN services, or website firewall on your website then you need to temporary disable CDN. When you disable, it removes the additional layer that created between your browser and the hosting server.

    Now, test whether your website loads correctly without it. If CDN services cause an error, then it will get resolved.

    Again enable, CDN and contact your CDN service provider to support.

    Method 6) Check Plugins and Theme

    Firstly, Deactivate your current Theme and switch it to a WordPress theme, to check that resolves the error. If not then Deactivate all WordPress plugins using the Bulk action from your WordPress Dashboard.

    You have to visit your site to see that the issue is resolved or not. If yes, then one of your plugins creates the problem. Now, you need to activate plugins one by one, to locate which plugin creates the error. You have to find out the alternative plugin or contact the plugin support to solve the error.

    Maybe your plugins or theme is outdated you have to update all to the latest version to get rid of this error.

    Method 7) Check your Host Server

    Sometimes script or a request takes too long time and so it’s killed by the server. When any request takes a long time to proceed, then the server kills it after some time so that it doesn’t take a site down or not affect other users.

    The reason to see the 502 Bad Gateway Error, then there is a problem with your hosting server. You need to contact your hosting provider’s support team and let them know the issue.

    We hope this article helps you to fix the 502 Bad Gateway Error on your WordPress site.

    Scroll to Top