If you run into a “502 Bad Gateway Error”, the problem is almost certainly an internal server error. It’s essential to understand the problem and, in some cases, there are a few measures you can take to resolve the issue. We’ll explain what this error means and explore ways to get things up and running again.

HTTP Status Codes

The 502 error code is part of the HTTP error response code set. HTTP or Hypertext Transfer Protocol is the core protocol that makes the web work. It’s part of the larger internet suite of protocols and describes how servers and clients talk to each other when requesting or sending web content. When your web browser (the client) requests data from a server using HTTP, and something goes wrong, the web server gives an invalid response resulting in an error code. The most famous of these is probably Error 404, which simply means the server can’t find a page at the address you’ve specified. 

The 5xx Error Code Family

There are five numbered sets of error response codes: 1xx, 2xx, 3xx, 4xx, and 5xx.

What’s a “Gateway”?

Error 502 Is a “Bad Gateway” Error. A gateway device is a node on a computer network that serves as a gateway to other web resources further upstream in the network. Your internet router or modem is a gateway device. So are the mega routers that your ISP uses to connect its users to the major trunks of the internet. If you want to know more about how it all fits together, read Who Owns the Internet? Web Architecture Explained. A “Bad Gateway” then simply means that the gateway device could not retrieve the data you asked for from upstream servers in the network. Bad gateway, bad! 

Common Causes of the HTTP 502 Error

The 502 error can happen for various reasons, but most are server-side problems. An overloaded origin server is by far the most common reason. An origin server is a computer that contains the website and listens for requests from users to serve that content.

Server Overload

There may be too many people making requests of the server simultaneously, so it fails to honor any beyond its capacity. You may even see a “502 service temporarily overloaded” error instead of “bad gateway.”

DDoS Attacks

Sometimes servers are overloaded on purpose during a DDoS (Distributed Denial of Service) attack, but the result is similar. If the server takes too long, it will count as a server timeout, and you’ll get an error code. DDoS attacks aren’t as common as they’ve been in the past, thanks to services like CloudFlare, that act as a buffer between a server and a flood of requests. So any overload you encounter is most likely legitimate high usage.

Server Misconfiguration

The server’s firewall or network settings may be misconfigured or erroneously identify your IP address as one that should be blocked. If you’re using a dynamic IP address (as most people do), you may have been assigned an address that a problematic user previously used. The internet is incredibly complicated, and there are dozens, even hundreds of networking equipment devices between your device and the server you’re trying to access. Some of them might be having trouble.

Buggy Servers

Finally, the server might actually just be down or have software bugs that make it unable to fulfill requests. Remember, a server is just a computer, and someone or something may have messed it up. So until someone debugs the software, the problem will persist. You’ll find hundreds of articles on the web detailing how to fix issues with Apache webserver software, plugging holes in PHP code, or resolving configuration issues with their WordPress sites. Now that you’ve got a good basic idea of the problem, we’ll look at the handful of things you can try when troubleshooting the issue.

Refresh the Page

If you’re faced with a 502 error, the first thing you should do is to refresh the web page. Most errors like this happen either because there’s a temporary network issue somewhere down the line or because the server is overloaded. You can also choose to wait until peak times are over (based on the time zone of the server location) before trying again. In 99% of 502 error cases, trying again later is the answer, but while you’re waiting, there are some other things you can do.

Check if the Site Is Down for Everyone

While a 502 error suggests that there’s a problem at the server’s end of the connection, it never hurts to make sure that you’re not the only one having issues. You can use websites like IsItDownRightNow? Or Down Detector to confirm that you aren’t the only one looking at an error code instead of the latest pictures of your mom’s dogs on Facebook. Some of these sites can show you important details such as how often a site goes down, whether it’s just down in certain regions, and whether any other users are complaining about specific problems at the moment.

Reset Your Router

Sometimes the bad gateway is the gateway in your house. Your router is a computer just like any other, which means it can hang, crash, or suffer from bugs. Like your other computers, a simple restart can usually resolve these issues.  Suppose you find that you have to reset your router often to get your internet connection working again. In that case, you may want to perform a firmware update or consider buying a new router with more capacity to handle lots of devices at once.

Clear Browser Cache and Cookies

 [9 Clear.jpg] Your browser keeps a cache of websites you visit often and those you’ve visited most recently. By maintaining a cache, you get faster site response times, and you’ll use less bandwidth to boot since you aren’t downloading common elements of the page every time you refresh or re-visit it. Unfortunately, web browser caches can go wrong and get in the way of loading a page properly. So you may want to clear your browser’s cache. Don’t worry about losing your history, passwords, and other important information. All clearing the cache will do is perhaps slow down site access for a bit until a new cache can be built up. If you want to know how to clear the cache for your web browser, check out our ultimate tutorial: How To Clear The Cache Of Any Web Browser Cookies are another type of data that your browser keeps locally that can interfere with website loading. Generally, cookies are good for the website experience. They let a website “remember” information about you so that you don’t have to log in every time or lose the contents of your shopping cart if your connection is interrupted. Apart from potentially messing up a site’s working, tracking cookies can also be a privacy problem, but either way, our tutorial How to Clear Any Web Browser’s History also shows you how to clear cookies. Just be sure to clear only the cookies and not your actual browsing history!

Update Your Browser

You should always keep your web browser up to date if only to make sure you have the latest security patches installed. If you have pending updates, complete them first before accessing the website that’s sending you an error. It might just be that your browser needs the latest web standards to speak to the latest website technology.  It can’t hurt to make sure your operating system is also up to date since there may be issues related to network drivers or the network stack for your computer or device.

Try a Different Browser

Not every browser is made equal. If you’re using an embedded web browser or some other lesser-known browser, it may not support all the functionality or requirements of a given website. It could also simply be that something has gone wrong with the browser you’re using. The fastest way to eliminate the browser as the source of the issue is to use a different browser. There are many to choose from, including Microsoft Edge, Safari (Mac or iOS), Mozilla Firefox, and Google Chrome, to name but a few.

Deactivate Plugins and Extensions

It might be worth starting up your browser or (temporarily) disabling all of your plugins and extensions to eliminate them as a source of the problem. Only do this if using a different browser without those extensions doesn’t show the problem on the same internet connection.

Try a Different Internet Connection

If the server you’re trying to reach is fine, but a gateway device on the route to that server is the source of the issue, you may want to force a different route by using a different internet connection.  For example, if your home broadband connection gives you the error, try accessing the site from your smartphone using your mobile data connection. Unless both connections are from the same ISP, this should bypass any ISP-specific issues.

Check Your Proxy Server

If you’re using a proxy server, the bad gateway in question could actually be that proxy server itself. Many workplace computers run through a company proxy server, and it’s not always possible to bypass these by design. After all, the company uses the proxy server to monitor what you do on the internet and control its information security. Suppose you can’t bypass your proxy server connection in the proxy server config. In that case, your only alternative is to check if the proxy server is working correctly by asking the IT department. If you’re using a private proxy service, turn it off to check if that’s causing the problem. If you’re running your own household proxy server, reboot it and check if it’s still configured correctly.

Try a VPN

While we like to refer to a “web server,” the truth is that most web content is hosted on multiple servers. Content Delivery Networks (CDNs) keep copies of web content on multiple servers spread worldwide. So when you request access to the site, the content is served by the CDN node closest to you, offering the best speeds and response times. It’s also cheaper to use local bandwidth rather than send data over international trunk lines, so companies favor using CDNs. The thing is, if your local CDN node is overloaded or having issues, you may get a 502 error. In theory, you’re supposed to be routed to the next working server node. But just in case, you can try using a VPN (Virtual Private Network) to access the website from another country or region within your own country. This may bypass the local server issue.

Flush Your DNS Cache or Change Your DNS Servers

DNS (Domain Name System) servers are like the telephone books of the internet. When you type an address like https://www.online-tech-tips.com (our sister site) into your address bar, the DNS server translates that into the correct IP address of the physical server that will send you the information you require. A given DNS server may have the wrong IP address on file (it may have changed), or the server it’s referring you to might be one of several for the site, and that one is having problems. Your local DNS cache might also be corrupted or out of date. You should first try to clear your DNS cache and try again. If that doesn’t work, you can change your DNS servers to see if that resolved the issue. Google’s Public DNS servers found at 8.8.8.8 and 8.8.4.4 are some of the fastest and most reliable DNS servers in the world. 

Use a Cached Page Instead

If all you needed from a website was static information, you might not need the server to be up and running at all. Google and other search engines constantly index the web and make cached copies of web pages. There are also websites such as the Internet Wayback Machine, which archives both old and new web pages so you can see the information they had at various points in time. It’s easy to see the cached version of a page using Google, just look for the three dots to the right of the result header and select it.  From the menu that pops up, choose cached. Then you’ll see a page with this message at the top.

Contact the Site Administrator

The last piece of advice we can provide when facing a 502 Bad Gateway error is to get in touch with the website administrator. If the problem seems to be with your ISP, you can contact their customer support and ask if they’re aware of any problems with access to that particular site. Many ISPs have a “known issues” section on their home pages or user account dashboards, so be sure to check these as well. In the end, if nothing in this article helps, it’s quite literally out of your hands, and all you can do is wait. So why not check out our Fun Stuff section for a few excellent ways to pass the time?

What Is a 502 Bad Gateway Error  And How to Fix It  - 34What Is a 502 Bad Gateway Error  And How to Fix It  - 31What Is a 502 Bad Gateway Error  And How to Fix It  - 88What Is a 502 Bad Gateway Error  And How to Fix It  - 37What Is a 502 Bad Gateway Error  And How to Fix It  - 62What Is a 502 Bad Gateway Error  And How to Fix It  - 73What Is a 502 Bad Gateway Error  And How to Fix It  - 49What Is a 502 Bad Gateway Error  And How to Fix It  - 72What Is a 502 Bad Gateway Error  And How to Fix It  - 58What Is a 502 Bad Gateway Error  And How to Fix It  - 68What Is a 502 Bad Gateway Error  And How to Fix It  - 59