Web Development

Error 502 bad gateway: how to fix it

By Pierre, on November 29, 2022, updated on June 1, 2023 - 4 min read

Similar to the 504 Gateway timeout error, the 502 bad Gateway error code indicates a problem on the web server side. There are several reasons why such an error message may appear. It can be due to :

  • an overloaded web server;
  • a navigation problem;
  • an error in our browser.

We have listed for you each of the causes of this error as well as the solutions to remedy it. Let’s discover them right now!

What is a 502 bad Gateway error?

The 502 bad Gateway error code appears in situations where the web server serves as a gateway. The processing of the client request in this case involves two servers. A main server (gateway server) and an upstream web server.

The 502 bad Gateway error indicates that the gateway server received an invalid response from the upstream server.

serveur
Photo by dlohner on Pixabay

The different forms of the 502 bad Gateway error message

The form that the 502 error message takes varies from one browser to another and from one server to another. It also varies from one website to another. You may therefore encounter various formulations that all say the same thing. Here are some of the most common forms.

  • 502 Bad Gateway
  • 502 error
  • HTTP 502
  • 502 Bad Gateway NGINX
  • Temporary error (502)
  • HTTP 502 error – bad gateway
  • 502 Bad Gateway Cloudflare
  • 502 proxy error
  • A black screen

502 bad Gateway error: what impact on SEO?

A 502 bad Gateway error that becomes repetitive on a website can have negative consequences on the SEO of the latter. Such an error affects the reputation of the website with search engines.

The user experience is bad and the bounce rate will increase. If the 502 bad gateway error lasts more than 6 hours, Google will consider this situation as a serious issue. The page will then drop in the search results ranking. It may even be de-indexed from search engines.

Photo by Firmbee on Pixabay

Error 502 bad Gateway : the causes

There are several reasons for a 502 bad Gateway error code. A web server that is not working properly or is out of order can cause a 502 bad Gateway error. This server malfunction may be due to a connectivity issue or too much traffic.

Note that if your website is overloaded, the server may be inaccessible and create a 502 error. Depending on your hosting package, server resources are allocated to you.

When your website exceeds the maximum quota of these resources, the service stops working. A 502 bad gateway error message may then be displayed.

DDoS attacks can also be the cause of this error. In general, their goal is to saturate the capacity of the web server so that it becomes inaccessible.

The 502 error can also be caused by a DNS issue. Incorrect DNS records prevent the domain from resolving to the correct IP address.

In addition, DNS changes take at least 24 hours to propagate. With your website unavailable during this time, the server may return a 502 bad gateway error code.

A plugin or an outdated version of the browser can also cause this issue.

Also read : How to fix Tachiyomi HTTP error 503?

What are the solutions to correct a 502 bad Gateway error?

For this type of problem, a real solution can only be found by the website administrator. But as a user, we can try some steps.

Refresh the page

The best way to solve the 502 bad gateway error is to refresh the web page. The website may have received much more traffic than usual. This has created a temporary malfunction. So let’s wait a few minutes and reload the web page.

Browsing in private mode

Restart the browser and open a new session in private mode. Let’s load the web page again. If the trouble comes from our browser, starting a private session should solve it.

Clear the browser cache and cookies

Corrupted files that remain on our browser may cause us to display a 502 error code. To solve the problem, simply clear the browser’s cache and cookies.

Try to load the page from another browser

Let’s try to access the target page with another browser. If the error code is no longer displayed, we can deduce that the failure came from the previous browser. Our problem could also be solved if we reinstall the browser.

Empty the local DNS cache

As mentioned above, a DNS malfunction can cause a 502 error code to appear. Deleting the files in the local DNS cache can remedy the problem.

The process for clearing the DNS cache varies from one operating system to another. To clear the DNS cache in Windows, simply go to the command prompt. To do this, type CTRL + R. In the search bar, type CMD and launch the command prompt.

Once in the command prompt, type :

ipconfig/flushdns

This command will delete all files stored in the local DNS cache.

Under macOS, let’s go to the terminal and type the command sudo killall -HUP mDNSResponder. At the end of the process, the DNS cache will be empty.

Check if the website is down for other internet users too

If the problem persists, let’s check if it is limited to us or if it affects other users. To do this, we can use tools such as IsItDownRightNow and DownForEveryoneOrJustMe. The results should tell us whether others experience the same issue.

Check the CDN

If you are using a content delivery network (CDN) as Cloudflare or Sucuri, the problem may be coming from there. Let’s check if CDN works properly.

To do so, go to the CDN dashboard and look at its live status. If the dashboard shows an error, the CDN is the one to blame for the trouble. We can contact their support team for further assistance.

Check the plugins on your WordPress site (or other CMS)

An outdated plugin or one that does not work properly on WordPress can prevent the website from loading. In this case, let’s deactivate all plugins and then reactivate them one by one. This should help us determine if the problem is due to a specific plugin.

Reboot the network devices

Restarting our connection equipment (modem, router, etc.) can allow us to access the target page. So let’s turn off everything up to the computer and turn it back on.

Contact the site administrator or the Internet service provider

If all the steps on our side result in the same error page, it means that the problem is not ours. The only remaining solution is to contact our internet service provider.

Perhaps one of its devices is causing this error. If this is not the case, we will contact the website administrator. He may be able to tell us why we can’t access his web page.

Pierre