Learn what Error 502 Bad Gateway is and how to fix it



What is 502 Bad Gateway error and how to fix it_ Managing websites built with WordPress is easy, but equally annoying when fixing errors. And one of the common ways is the 502 Bad Gateway. The 502 Bad Gateway error is likely to break your site and take some time to fix this problem. And here we will together with you to find out details about this 502 error and how to deal with it.


What is 502 Bad Gateway error?


To understand 502 Bad Gateway, you should know how the browser downloads data from the server. When the user accesses the web, the server sends a request to fetch data needed to display the content in the browser. The server correctly responds to requests and receives the requested content, otherwise, Error 502 Bad Gateway appears.


WordPress sites running on multiple servers are allotted for a specific task. For example:


  • Database server for WordPress database

  • Application server to run PHP and other application related content

  • Reverse proxy server is responsible for Nginx, Apache, Varnish

  • Web server to serve web files

Multiple servers together can complicate the way the browser handles requests. Upon receiving the request, the reverse proxy server will fetch data from the root server such as database server, application server, web server.


If any one of these servers sends an invalid response, the reversed proxy server will return to the browser and display 502 Bad Bateway.


We often see Error 502 different on different websites, but all are at the same point: the server cannot respond to the requests. Let's take a look at some examples that this error displays.


  • “502 Bad Gateway”

  • "HTTP Error 502 Bad Gateway"

  • “502 Service Temporarily Overloaded”

  • "Error 502"

  • "502 Proxy Error"

  • "HTTP 502"

  • “502 Bad Gateway NGINX”

  • "502 Server Error"

  • “502. That’s an error. ”

width =


Twitter displays 505 Bad Gateway in a more friendly way.


width =



Google displays 505 Bad Gateway error with suggestions to try again after a while.


width =


We now understand what Error 502 Bad Gateway is. Let's explore the cause of this error and how can we fix it in WordPress?


Why does 502 Bad Gateway Error occur in WordPress?


We receive Error 502 Bad Gateway when the server has not responded correctly and returned the request with invalid information. However, there are also other possibilities, for example:


  • Your server is busy with other tasks or affected by heavy traffic from a specific web (in case of shared hosting)

  • Root server unresponsive, unreachable

  • Error in database

  • Problem with proxy server

  • PHP scripts are broken in files like WordPress themes and plugins.

  • DNS problem

The above capabilities can lead to WordPress 502 Bad Gateway error. However, handling any error becomes more difficult if you do not know the factors involved in triggering the error.


We talked about what Error 502 is and why does it happen? Next, we will share directions to fix the error.


Fix 502 Bad Gateway error


  • Check if the web server is responding

The first thing you need is to check if your web server is responding. The easiest way to find out if your server is really the culprit is to run an online scan. Visit the website 24x7 and enter your web host name.


loi-502-bad-gateway-what-is-the-other-way


Many locations will ping the server and show you statistics such as Load Time, Response Time.


Another way to test web server responsiveness is to manually ping using SSH.


Just access SSH, terminal and run the following command:


ping (server IP)


Now, replace the server IP of the IP with your server IP address.


width =


If your server responds, it will display ping every time.


Sometimes any query or task takes longer than usual; The server canceled it and returned with 502 Bad Gateway Error. It is common in shared hosting and the provider will kill the script to avoid any ill effects on other websites hosted on the same server.


Sometimes just by reloading the website, you can save hours of troubleshooting!


Maybe you get an overloaded server for a while and when you check back in a minute or so, it should work again.


Also, confirm if the site doesn't work just for you or for others. To do this, simply check the URL on Down For Everyone Or Just Me.


The browser has the ability to save web data so that the next time a user accesses it, there is no need to download the same static resource again. It is an effective way to use resources, but it also has some disadvantages.


Let's say you went to another browser and the site loaded fine. Knowing that your website loads correctly, you return to your default browser, but the problem persists.


That's because the browser is showing you a cached copy from that web. To fix that, simply clear your browser cache.


See more: How to add related posts in WordPress


  • Search for DNS issues

Domain name system stands for DNS is a way of linking domain names to IP addresses. If the domain name cannot find the correct IP, it will display Error 502 Bad Gateway. We can see this error when moving WordPress website to new server, request to change DNS name server.


Changes usually take 24 to 36 hours to receive. During this time period, if you try to access your site, you will encounter a WordPress Error 502 Bad Gateway.


We can clear DNS cache from the Windows Command Prompt. In Windows OS, run the command ipconfig / flushdns to clear the DNS cache. In Mac OS, run the command as dscacheutil -flushcache inside the terminal window.


CDNs are widely used to serve static content of websites. This is a useful technique to deliver web content faster to a global audience. However, the CDN may be one of the reasons for WordPress 502 Bad Gateway Error due to an extra layer between server and browser.


To overcome this you just need to disable the CDN service and then try to access your website. You only need to contact CDN support and if not, then we recommend you continue to follow the rest of the article.


Themes and plugins play an essential part in any WordPress website. It is almost impossible to have a fully functional web without adding Themes and plugins. They can also become a reason to create WordPress 502 Bad Gateway errors.


Themes and plugins, which contain incorrect PHP code, can cause problems that the server does not understand or take too long to process. This results in 502 Bad Gateway error.


Start by deactivating all plugins from FTP. Just go to the root directory where the WordPress files are installed, i.e. the public_html directory, navigate to wp-content → plugin and rename the plugin directory, thus the WordPress system cannot be accessed.


loi-502-bad-gateway-what-is-the-other-way


Now check the website and if it loads properly, then start activating them one by one until you find the one that is causing the problem.


If you find no faulty plugins, then go ahead and search for a faulty interface. In your wp-content directory, navigate to the topic and rename your enabled topic to deactivate it. Removing it may not be the right choice because reuploading may take custom styling.


loi-502-bad-gateway-what-is-the-other-method


Now go back to your website and if you see a blank screen instead of an error, then Vola! Your topic was causing the problem. Log in to your wp-admin and activate the default theme.


WordPress logs are very useful when dealing with errors. You can enable error logs when adding code to the wp-config.php file.


define (‘WP_DEBUG’, true);


define (‘WP_DEBUG_LOG’, true);


define (‘WP_DEBUG_DISPLAY’, false)


When PHP reaches the maximum time in the server configuration to execute the script, it displays an error. Sometimes it is possible to activate WordPress 502 Bad Gateway Error. To avoid this, simply increase the maximum execution time value. By default, this is set to 300 seconds, which is 5 minutes.


We create features, custom skins in WordPress. These custom functions are sometimes the reason the server cannot handle them. Also, calling a third party API like Google reCAPTCHA, creating long tokens can be stressful for the server and it returns with 502 Bad Gateway Errors.


Conclude


We hope after reading the article, Error 502 Bad Gateway will not be scary next time you see it. Troubleshooting is easy if you can predict the source and use the techniques listed in this article for troubleshooting.