fb-pixel

502 bad gateway: how to solve it

Published in:

by:

The 502 bad gateway error is a type of HTTP error that notifies the user that there is some kind of problem in reaching the requested web page.

The causes of this error are varied, and it is one of several problems that fall under the category of server-side errors. In this article,  we are going to see the reasons for this kind of error, how to detect it and what solutions we have at hand to solve it.

We’ll see what we can do in order to solve or avoid the problem both in case we are surfing on someone else’s website and in case the error is found by a user surfing on our website.

In addition, we will see what specific strategies we can implement when we encounter the 502 bad gateway error in WordPress.

502 bad gateway: the meaning of the error

While browsing, your browser sends requests to a server, which in turn manages incoming requests and provides the response with codes indicating the status of the request.

When the request is successful, the server responds with code 200, but it does not appear to the user. For this reason, when the procedure is completed correctly, the only thing you’ll see is the content of the site or page you intended to visit.

If, however, there is an error, you will be shown a notification warning you about the type of error encountered. In some cases, you will be shown a generic error, for example when browsing with Chrome you may encounter the classic Chrome Aww Snap error. In other situations, you may have to use the Windows network diagnostics to identify the cause of the error, for example, if the DNS server is not responding.

In other situations, however, the error message will also contain a number corresponding to a type of problem: for example, codes with error 400 are client-side errors. One of the most classic examples is when a page is not found and error 404 is shown or error 403 when you are denied access to the server.

Conversely, those ranging from error 500 to 511 are server-side errors. Among them, there is also the 504 gateway time-out that always involves the server. But what does it mean?

Let’s first make a premise by briefly explaining how the network works. As we said when you try to open a site your browser sends a request to a server, this works as a proxy and connects to the server on which the site is hosted.

When the process of handling the request encounters some kind of error, you will be shown a corresponding error code, warning you that something has gone wrong.

502 bad gateway: variants of the same error

This type of error is called error 502 bad gateway because 502 is the HTTP status code that is used to identify the problem in question.

Error 502 can be accompanied by other captions that help denote it better, for example, “bad gateway” or “502 bad gateway nginx” or “502 bad gateway apache“.

In other cases, however, this type of error might appear simply as “Error 502” or “502 Proxy Error”. In almost all cases, however, the error code is specified and this helps us to understand what kind of problem we are experiencing and especially to distinguish it from other types of errors.

Error 502 can have different wording, the most common ones are:

  • Error 502
  • 502 Error
  • 502 server error
  • 502 Bad Gateway
  • 502 Bad Gateway Nginx
  • 502 Bad Gateway Apache
  • 502 bad gateway Cloudflare
  • HTTP 502
  • HTTP Error 502 – Bad Gateway
  • 502. That’s an error
  • 502 Proxy Error
  • 502 Service Temporarily Overloaded
  • 502 Server Error: The server encountered a temporary error and could not complete your request
  • Temporary Error (502)
  • 502 – Web server received an invalid response while acting as a gateway or proxy server
  • Bad Gateway: The proxy server received an invalid response from an upstream server
  • A blank white screen.

Error 502 bad gateway is one of the most frequent problems that can be encountered while browsing and it indicates that the server fails to forward the request to the main server.

However, it is not clear at what point in the process exactly the error occurs. The causes of this error message, in fact, are varied, let’s see what they are.

What causes the 502 bad gateway error

Error 502 bad gateway belongs to the category of generic errors that fall under the 500 codes, but it is a communication error between servers, so these errors are to be attributed to the server and not to the client.

In many cases, therefore, as users, we will have little to do to solve this type of problem. However, as we will see, there are several causes that lead to this kind of errors, some of which can be solved.

In particular, in the case of the 502 bad gateway error, the problem is due to the fact that the server acting as a proxy or gateway has received an invalid response from the server hosting the site. But what is this incorrect response due to?

A system crash of the server

The non-response or invalid response received by the gateway from the server may be due to the fact that the server has suffered a system crash.

More rarely, there may be cases where the server has been taken off the web. In this case, therefore, the error depends on the destination server, i.e. the one hosting the site.

Server overload

One of the most frequent reasons that can lead to the 502 bad gateway error is a server overload that cannot handle the numerous requests received.

This can be due to either a true overload of users or a DDoS attack, by hackers trying to “DDoSing”  the server.

Programming errors

Even an error present in the PHP programming of the target site can go on to generate a failure to resolve requests received from the server and thus cause a 502 error.

A firewall problem

Even firewalls can generate errors, and besides being in some cases responsible for client-side errors such as the dns_probe_finished_nxdomain, can also be the cause of server-side errors.

For example, this error may be due to an incorrectly configured firewall, which therefore prevents proper communication between the gateway and the server.

A browser error

The real culprit of the 502 bad gateway error, at least in some cases, could be the browser itself that you are using. On certain occasions,  the browser or the extensions used in it can generate errors, including the error code in question.

502 bad gateway: fixing the error

Now that we have analyzed what 502 bad gateway means and what are its main causes, let’s see what operations you can do to solve the problem.

502 Bad Gateway Server Error

As it is easy to see, addressing this problem can be useful both to those who take care of their website and to the user who comes across the error. So let’s see what solutions you have available in the two cases.

502 bad gateway error: how to solve by user

The first solutions that I propose in this part of our article can be applied in case you want to try to solve, or avoid, the error 502 bad gateway. First of all, it must be pointed out that, in most cases, this is a temporary error, so it is likely that within a short time the error will disappear on its own.

However, there are several strategies you can use to get around this problem if you need to or if the error lasts longer. Let’s see how.

Reloading the page

The first, and simplest, thing to do when faced with a 502 bad gateway error is definitely to try reloading the web page. So, wait at least a minute and then reload the page in your browser through the appropriate button, or by pressing F5, the shortcut key that works in most browsers such as Google Chrome, Mozilla Firefox, etc. for computers with Windows and Linux operating systems.

If you are using MacOS, you can use the Command + R key combination to refresh pages in most browsers (Safari, Chrome, Firefox, etc.).

In the event of a server overload, it will not be enough to reload the page after a few minutes, but you will have to wait about fifteen minutes for the server to be “available” again.

Emptying the browser cache

Just as I explained to you about the causes that can generate this problem, in some cases, the browser can be responsible for this error. For this reason, another possible solution to solve the 502 bad gateway error is to try clearing your browser’s cache.

The operation varies from one browser to another, but in most programs, you can also clear the cache of even a single page. To do this just use the key combination CTRL + F5, this way only the cache of the page you are visiting is emptied, while the rest remains unchanged.

This key combination works on Windows and Linux, on Mac instead to “bypass” the cache you need to hold down the Command and Shift key and press R at the same time.

In a dedicated article, I explain, instead, how to clear the cache of the main browsers with the procedure step by step.

Use another browser or reinstall the one you are using

Sometimes changing browsers may be required to rule out the possibility that the cause of the problem is the very browser you are using. In this case, if the site is reached without errors using a browser other than the one you usually use, it may be necessary to reinstall it to restore the basic settings.

Before reinstalling the browser, however, you can check that there are no plugins or extensions that interfere with its proper functioning.

Start the browser without extensions

To verify that the cause of the 502 bad gateway error is not due to interference from extensions you will have to disable them, at least momentarily, and see if the problem occurs again.

This is also one of the ways you can use to solve other types of errors like err_connection_refused.

When using Chrome, for example, you can use incognito browsing or private browsing which will automatically disable the various extensions and thus see if the error recurs.

In Firefox, on the other hand, you can start the troubleshot mode (also called safe-mode) that will let you start the browser without the additional themes and extensions. To start this mode you can go to the “Help” options from the menu with the three dashes and select the item “Troubleshoot Mode…”.

502 Bad Gateway Firefox Troubleshoots Mode

After that you’ll just have to confirm by clicking on “Restart”.

502 Bad Gateway Restart Firefox Without Addons

Alternatively, you can also start Safe Mode from the Command Prompt on Windows or from the terminal on Linux or Mac. For Windows computers there are several ways to start the Command Prompt: on Windows 10 you just have to search for it in the search bar and press enter, or, in general, from “Run” you just have to type “cmd”.

502 Bad Gateway Prompt

Once the Command Prompt is open you can start both Firefox and other browsers in safe mode directly with the specific commands.

In the case of Firefox you will have to enter the path of the executable file (firefox.exe) of the browser (C:\Program Files\Mozilla Firefox\firefox.exe) followed by the topic – safe-mode. And then you’ll have to click on “Open” as shown in the example below.

502 Bad Gateway Firefox Troubleshoot Mode

After starting the browser in safe mode, if you can access the site without running into the 502 bad gateway error again, then most likely the problem was caused by some extension. If, on the other hand, the problem recurs, then it does not depend on the extensions or themes you have installed on your browser.

In the first case, in order to find the extension that is responsible for the error, you have to disable them one by one until you find the one that causes the problem. In order to do that you will have to access the Extensions panel by clicking on the menu (corresponding to the symbol with three dashes), then on Add-ons and from there select Extensions from the menu on the left.

502 Bad Gateway Firefox Extensions

Then you can click on the button next to each extension to disable/reactivate it.

502 Bad Gateway Deactivate Firefox Extensions

NOTE:  When the extensions are active the icon is blue and it appears in the list of active extensions.For the deactivated ones the icon is grey.

Remember that most of the errors generated by plugins (but also by themes and extensions in general) can be due to their obsolescence, for this reason always remember to keep them updated.

Restarting your router and/or pc

In case the site is online and your computer can’t access it, even though you have tried using different browsers, it may be helpful to try restarting your router and computer. In this case, if it is a temporary problem, it may resolve on its own.

However, the question is, how can you tell if the site you are trying to visit is really online or if the problem is upstream? Well, let’s see in the next paragraph.

Check if the site is working for others and not for us

When you are faced with a 502 bad gateway error, it can be useful to know if the site you are trying to reach is online.

To know if the site you’re trying to visit is active or not you can use one of the services provided by the network such as the one offered by Down for Everyone or Just Me. Just copy and paste or type the address of the site in the search bar to see if it is online or not. In this way you’ll understand if the problems you’re experiencing are actually due to the server that hosts the site or to other causes.

Error 502 Bad Gateway Down For Every One Or Just Me

Another service that you can use to check if a website is active is Is It Down Right Now, also in this case using it is very simple. All you have to do is enter the domain of the website you’re interested in and you’ll get information about the current status, the response time and the last time the website was offline.

Error 502 Bad Gateway Status Check

Change DNS server

Another possible cause of the 502 bad gateway error is a DNS server problem, in this case, manually change the DNS to get around the problem. Changing DNS servers from those offered by your provider to public ones, such as Google or Cloudflare ones can solve your problem. To change DNS servers on Windows and Android I refer you to the detailed procedure described in my article on how to fix DNS_PROBE_FINISHED_NXDOMAIN error.

Access to the cache copy of the site

If you are unable to access the website you are looking for, and the error 502 bad gateway remains even if you have tried the various solutions proposed so far, know that you have the possibility to access the last version of the site saved in the cache of search engines.

In some cases you can also exploit the cache of search engines, such as Google and Bing, to find pages or entire sites no longer online. To do this, after searching for the site that interests you on Google, for example, you just click on the down arrow next to the address of the site and then click on “Copy Cache”.

502 Bad Gateway Google Cache

Similarly, if you use Bing as your search engine, just click on the arrow next to the address and then on “Cached”.

502 Bad Gateway Bing Cache

Error 502 bad gateway how to solve by webmaster

If you are not experiencing the 502 bad gateway error yourself, but a user is unable to access your website, you should try to identify the cause of the error.

After verifying that your server is up, the first thing you can do if your site is down is to contact your hosting service.

Check that there are no problems with the host

In most cases, the 502 error may be due to the hosting service on which your website is based on. There are cases where scripts have to be loaded in order to reach a page, but they take too long.

Some hosting services use a system, called kill script to stop these requests that take longer than necessary.

This type of script, used in some cases by shared hosting, can generate errors and prevent access to shared sites or resources.

Check error logs

The 502 bad gateway error can also be due to internal errors present on your site. The first thing you can do to make sure there are no such issues is to go check the error log. If you’re using WordPress, you can enable the error log and keep track of what’s happening on your site. To do this you’ll need to edit the wp-config.php configuration file by going to add the following code:

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

Check PHP programming

Another thing to do is to check the PHP programming of your site for errors.

For example, you can check that there are no timeout issues that go to terminate some processes, in a scheduled manner, after a certain period. To do this you will need to check your PHP configuration and determine if you should set a longer timeout time.

Also, if your hosting service allows you to do so, you can restart PHP or ask the host to do so, and see if the problem is resolved by the restart.

Controlling the CDN

Another possible solution may be to temporarily disable the CDN, i.e. the Content Delivery Network. In fact, error 502 can occur due to the use of Ddos protection services and firewalls included in third-party CDN networks such as those employed by GoDaddy and CloudFlare.

To give an example, in the case of CloudFlare the 502 bad gateway problem can occur in two distinct forms.

Error 502 Cloudflare

In one case, as in the example above, it depends directly on CloudFlare and so it’s not possible to fix it yourself, unless you contact customer support.

Error 502 Bad Gateway Cloudflare

In the second case, instead, CloudFlare warns you through an error message like the one you see above, that the problem is due to the hosting.

Check plugins and themes in WordPress

In some cases, the use of plugins or themes with wrong configurations can generate the appearance of errors like this one. To solve the 502 bad gateway error in WordPress you can first try to deactivate the plugins you use, to check if they are the ones responsible for the problem. To disable all plugins, you can go to the admin panel, select all of them by clicking on the box at the top and then through the menu of “Group Actions” select the option “Disable”.

502 Bad Gateway Deactivate WordPress Plugins

After deactivating all plugins, to identify which of them causes the error, you will have to reactivate them one by one.

To prevent plugins and other WordPress extensions from causing errors it is important to remember to keep them updated and to check that they do not conflict with your version of PHP.

Conclusion

In this article, we have seen what the 502 bad gateway error means, examined what are the main causes and seen how to fix them.

When did you come across this error: while surfing the web or was it when your website presented such an error? Were you able to fix it by following any of these steps? Did you have to contact your host? Let me know in the comments below.


Try one of our hosting plans for free and without obligation for 14 days. No payment information required!

Comments

Leave a Reply

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