How to resolve 502 Bad Gateway Error?

Updated on September 24, 2021

The HTTP status code 502 Bad Gateway indicates that one server has received an incorrect response from another server. 502 Bad Gateway failures are entirely independent of your specific setup, which means you could see one in any browser, operating system, or device.

This error regularly happens throughout the web network on different CMS, including WordPress, Magento, and many more.

1) How the 502 error look like?

There are many ways this error showed on the website browser. Few examples are given below:

  • 502 Service Temporarily Overloaded
  • 502 Bad Gateway NGINX
  • HTTP 502
  • 502 Error
  • 502 Server Error: The server encountered a temporary error and could not complete your request.
  • HTTP Error 502 – Bad Gateway: The proxy server received an invalid response from an upstream server.

2) Why are we facing 502 Errors?

There are several reasons why the 502 error appears in the browser. Which are explain below:

DNS issues or Domain not resolved:

Sometimes the domain is not resolving to the correct IP, or it does not resolve to any IP. The Domain Name Systems can take 0 – 24 hours to become fully activated globally.

The Server is not reachable:

It can happen due to several reasons such as the server being down, no connectivity to the server, sudden/planned heavy traffic, or the server being unable to communicate due to maintenance.

The server transmission is being blocked by the firewall:

A firewall is in place to block transmission between servers, and its primary purpose is to protect against DDOS and other hacking attempts. Sometimes, a firewall can make a mistake by not distinguishing between safe content for malicious content and stops the safe content in its tracks. There might be a plugin or extension depending upon the CMS which you are using on it.

3) What are the troubleshooting steps to resolve this issue?

a) Refresh the Page

Please wait around for a few minutes and refresh the page on the browser. majority of the time, the error is temporary, and a simple page refresh will do the work.

b) Clear Browser Cache

If the first step does not resolve the issue, then there is a chance that a specific cached file is causing the issue. Therefore, removing the cache from the browser is the second step when a 502 bad gateway error shows up.

c) Try a Different Browser

Checking the connection using a different browser or incognito mode is also a great idea. It will let you rule out the option that the 502 error appeared due to a browser-related problem.

d) Flush DNS

The 502 bad gateway error can also pop up due to DNS issues, such as incorrectly cached IP address values. For this case, it is recommended to contact the DNS registrar and ask them to flush the cache against their domain.

Before flushing the DNS cache, kindly check the A record of your domain name via If the server’s IP is correct or the IP of a firewall server like Cloudflare is correct if you are using the firewall or any security service, then flushing a DNS cache is not required. If the A record of DNS is incorrect, kindly flush the DNS cache via submitting a query to the Domain Registrar.

Kindly note the DNS record will take 0 – 24 hours to propagate globally. You can also check the status of the DNS record via

e) Check Error Logs

The 502 error can appear after any change or update, and the fault may lie within the website files. For this case, it is recommended to check the error logs of the application.

Note: To connect your application via SSH, kindly visit our knowledge base article on How to connect your application via SSH and SFTP.

The error logs of the application can be found inside the application folder.

Command: cd applications/application_folder_name/logs/

To view the logs: tail –f error.logs

  • Plugin Error:

If the error logs show the issue due to a plugin, follow the below tricks.

If you are unable to connect to wp-admin, you still have the option to deactivate the plugin(s) one by one via SSH or SFTP.

Go to cd applications/application_folder_name/public_html/wp-content/plugins and rename the compromised plugin.

Command: mv plugin_folder_name plugin_folder_name-back

  • Theme Error:

If the error logs show a theme related, follow the below steps:

Go to cd applications/application_folder_name/public_html/wp-content/themes and rename the compromised theme or change the current theme with the default theme from wp-cli, then run the following command using SSH.

Command:  wp theme activate twentytwentyone

Now open the site in incognito mode. If the site is working, it means the issue is coming from the theme, so you will need to contact the theme’s author or your web developer to look for an alternative.

f) PHP Timeout

If you are importing WordPress files, you could see error 502 bad gateway. This will happen when a single PHP process runs longer than it should. The max_execution_time (max_input_time) is in your PHP configurations on your web server.

Talk to your hosting support team as if you want to know what your values are set at and if you can increase them or not.


In this knowledge base, we have shared all the steps to troubleshoot the 502 bad gateway error. But if the issue is still coming on the site, please feel free to contact our support team. 

Need More Help!

Type in your question at the knowledge base website or comment below

Leave a Comment

Your email address will not be published. Required fields are marked *