What is a 502 Bad Gateway Error (And How Can I Fix It)?

6 min


0
228 shares

What Does 502 Bad Gateway Mean?#

A 502 Bad Gateway indicates that the edge server (server acting as a proxy) was not able to get a valid or any response from the origin server (also called upstream server). This can occur for a few reasons, which we’ll discuss in the section below. If one of KeyCDN’s edge servers receive a 502 Bad Gateway response from your origin server, KeyCDN will return a 500 Origin Not Reachable page. To get a better understanding on how KeyCDN handles certain error codes, check out our CDN Error Codes page.

What Are the Reasons for 502 Bad Gateway Responses?#

There are 3 main culprits that cause 502 Bad Gateway responses. These include:

  1. Domain name not resolvable: The domain name is not resolving to the correct IP or it does not resolve to any IP. It is important to note that DNS changes could take same time until they are global fully propagated and active. This is dependant on the TTL, or time to live, defined per record.
  2. Origin server down: The server is not reachable, either because it is down or there is no connectivity to the server given.
  3. Firewall blocks request: A firewall blocks the communication between the edge servers and the origin server. This can also be caused by security plugins of your CMS. Some DDOS protection and mitigation systems might are too overreactive and start blocking requests from our content delivery servers.

How You Might See a 502 Bad Gateway Error#

Based on your web server, you might see a different 502 error.

These all mean the same thing, it is only their naming conventions that differ. Here are a few examples of what you might see:

  • “502 Bad Gateway”
  • “HTTP Error 502 – Bad Gateway”
  • “502 Service Temporarily Overloaded”
  • “Error 502”
  • “502 Proxy Error”
  • “HTTP 502”
  • “502 Bad Gateway NGINX”

You can see in greater detail what the error specifically entails by going to your web server’s error log file. All error / diagnostic information is stored in this file making it a valuable resource to check when you need more details about a particular error. You can locate this file in Apache by going to /var/log/apache2/error.log and in Nginx by going to /var/log/nginx/error.log.

How to Solve 502 Errors – for Web Developers#

As a web developer or owner of the website, there are a few reasons why you may be experiencing a 502 Bad Gateway error on your origin server. Therefore, you may need to try various methods to resolve the issue. Reference the list of suggestions below:

  • Check if your FQDN (fully qualified domain name) is resolving correctly by using our DNS test tool.
  • Verify if your server is reachable by using a ping test or trace-route.
  • Check your firewall logs if you are seeing unusual drops.
  • If you’re a Cloudflare user, try disabling it as once you’ve reached a certain limit Cloudflare will return a 502 Bad Gateway error to your visitors.

How to Solve 502 Errors – for Visitors#

If you’re a website visitor and experience a 502 Bad Gateway error then there is also a few things you can try to resolve it. Although the primary issue will almost always be the responsibility of the web developer, visitors can try the following:

  • Perform a hard-refresh in your browser. On Macs, this is done by pressing Cmd + Shift + R.
  • Clear your browser cache and delete cookies. Your browser may be holding on to certain files that were saved once you visited the website with a 502 error.
  • Restart your computer/networking equipment
  • Change your DNS servers. If you’ve never changed them in the past you likely still have the default servers assigned to you by your ISP, try using open DNS servers such as Google’s Public DNS.

A 502 Bad Gateway Error occurs when you try to visit a web page, but one web server gets an invalid response from another web server. Most of the time, the problem is on the website itself, and there’s not much you can do. But sometimes, this error can occur because of a problem on your computer or networking equipment. Here are some things you can try.

What is a 502 Bad Gateway Error?

A 502 Bad Gateway Error means that the web server you’ve connected to is acting as a proxy for relaying information from another server, but it has gotten a bad response from that other server. It’s called a 502 error because that’s the HTTP status code that the web server uses to describe that kind of error. These bad responses could be due to a number of different causes. It’s possible the server is overloaded or there are network issues between the two servers, and it’s just a temporary problem. It’s also possible there’s an improperly configured firewall or even a coding error, and that the problem won’t get fixed until those issues are addressed.

Just like with 404 errors, website designers can customize how a 502 error looks. So, you might see different looking 502 pages on different websites. Websites might also use slightly different names for this error. For example, you might see things like:

  • HTTP Error 502 Bad Gateway
  • HTTP 502
  • 502 Service Temporarily Overloaded
  • Temporary Error (502)
  • 502 Server Error: The server encountered a temporary error and could not complete your request
  • 502 Bad Gateway Nginx

The vast majority of the time, this is just an error on the server side of things that you won’t be able to do anything about. Sometimes, it’s a temporary error; sometimes it isn’t. Still, there are some things you can try on your end of things.

Refresh the Page

Refreshing the page is always worth a shot. Many times the 502 error is temporary, and a simple refresh might do the trick. Most browsers use the F5 key to refresh, and also provide a Refresh button somewhere on the address bar. It doesn’t fix the problem very often, but it takes just a second to try.

Check If the Site Is Down For Other People

Whenever you fail to reach a site (for whatever reason), you can also check if it’s just you that’s having a problem connecting, or if other people are having the same trouble. There are lots of tools out there for this, but our favorites are isitdownrightnow.com and downforeveryoneorjustme.com. Both work pretty much the same. Plug in the URL you want to check, and you’ll get a result like this.

If you get a report saying the site is down for everyone, there’s not much you can do but try again later. If the report shows that the site is up, then the problem might be on your end. It’s very rare this is the case with a 502 error, but it is possible, and you can try some of the things we describe in the next few sections.

Try Another Browser

It’s possible that an issue with your browser might be causing the 502 Bad Gateway error. One easy way to check this out is to use a different browser and see if it works. You can use Google ChromeMozilla FirefoxApple Safari, or Microsoft Edge. If you can see the error in the new browser as well, then you know it’s not a browser issue, and you should try another solution.

Clear Your Browser’s Cache and Cookies

If trying a different browser works, it’s possible that your main browser has cached outdated or corrupt files that might be causing the 502 error. Removing these cached files and trying to open the website could solve the problem.

clear-cookies

Check Your Plugins and extensions

If you use extensions on your browser, then it’s possible that one or more of the extensions are causing the problem. Try disabling all your extensions and then accessing the website. If the error disappears after that, then its likely that a plugin is causing the issue. Enable your plugins one by one to find the culprit.

browser-extensions

Restart Your Devices

So, you’ve used a site checking tool and determined that the site is just down for you. And, you’ve tested another browser and are having the same problem. So you know the problem is likely something on your end, but it’s not your browser.

It is possible that there are some strange, temporary issues with your computer or your networking equipment (Wi-Fi, router, modem, etc.). A simple restart of your computer and your networking devices might help fix the problem.

Change your DNS Servers

Sometimes, DNS problems can cause 502 errors. Changing your DNS servers is not a likely fix, but it is a possible one. And it’s not too hard to do. Unless you’ve changed them yourself, your DNS servers are probably be set by your ISP. You can change them to a third-party DNS server like OpenDNS or Google DNS, and that might to solve the problem. And there are other reasons you might want to change DNS servers, too—like better speed and reliability.


Like it? Share with your friends!

0
228 shares
Sande Kennedy

Sande Kennedy is the founder and Editor in Chief of SandeKennedy.com & Kenyans247.com He is a Kenyan-based Internetprenuer,blogger Political Activist & informer who has an interest in politics, governance, corporate-fraud and human-interest. Kindly drop me a note if you feel aggrieved on any matter that you would want to be highlighted  Twitter: @itssandekennedy , Instagram: @itssandekennedy WhatsApp: +254791890826 Read More about me here
Open chat
1
Would you like to get published on this Popular Blog? You can now email Sande Kennedy any breaking news, Exposes, story ideas, human interest articles or interesting videos on: info@sandekennedy.com. Videos and pictures can be sent to +254 791890826 here on WhatsApp by clicking this send button
Powered by