Error 502 Bad Gateway: Where’s the problem?
Everything doesn’t always run smoothly when surfing the net. Now and again, you’ll visit a website and instead be greeted by an HTTP status code. Something went wrong! If you run up against a 500 code as an internet user, then in most cases the problem is not with you or your internet connection — it’s far more likely that it’s the website’s server instead. With a 502 error, though, it can occasionally happen that something is wrong with your settings — especially if you’re suddenly receiving the annoying status code regardless of which sites you’re trying to access. This article gives you tips on how to suss out the source of the error and what you can do as a user to once again view the content of the website. Or are you the operator of an affected website? We’ll tell you how to check for that error too.
What does ‘bad gateway’ mean?
The internet protocol HTTP generally provides status codes in response to queries. The most common code is probably number 200: OK. Everything has worked as it should. This status isn’t usually shown to users, though. Instead, visitors simply see the requested website content. On the flip side are the error messages: While 400 codes imply that the error lies on the client side, 500 to 511 codes mean that the negative result is the server’s fault. The status codes also indicate where the error occurred — at least to users who know what the individual codes mean.
The 502 error is usually provided with the addition Bad Gateway or as a “502 Bad Gateway Nginx”, “502 Bad Gateway Apache”, or “502 Bad Gateway registered endpoint failed to handle the request” message. Next to the well-known 404 error (“Page not found”), the bad gateway error is one of the most common error messages received when surfing the internet. It’s delivered when the server, which is accessed via the main server, couldn’t forward the request. In this case, the first server functions only as a proxy or gateway. In principle, all queries on the internet are forwarded via gateways. That’s why this error message is often so frustrating: It’s generally not at all clear at which point in the process the request encounters the error.
What are the sources of the 502 Bad Gateway error?
In most cases, the bad gateway error occurs on the server side and can’t be fixed by the internet user. But it’s also possible that the browser being used has registered a 502 error where really none exists. It’s also possible that you’re disconnected from your network. The following reasons could explain why the infamous HTTP code is displayed:
- Server failure: The gateway receives a negative result if the target server has failed completely, among other things. This can occur due to a system crash. In rare cases, servers can also be taken offline spontaneously — for example, when the content is in violation of a law.
- Webserver overload: If a webserver reaches its limit, it can’t answer any more requests — the gateway then delivers the status code 502 Bad Gateway. The reason could be an unexpectedly high interest in the site or even a DDoS attack. This means that an attacker is using a bot network to help overload the server capacity and provoke a system failure.
- Faulty PHP programming: Occasionally, there’s an error in the website’s code. Certain requests will then not be answered correctly anymore, delivering a negative result instead.
- Communication error: Firewalls can cause errors on both sides of the communication (server and client) with the forwarding of requests.
- Browser error: Browser extensions can also sometimes cause errors with the display of a website and generate a 502 error.
Fixing the 502 error
Internet users, as well as webmasters, have the ability to respond to a bad gateway situation. In many cases, just waiting for a little while is enough. Often, the error occurs outside of your sphere of influence and is solved by the internet provider (ISP) or the hosting provider of the web server without any intervention on your part. But sometimes the error is on your side, so you should know where to begin to search for the cause.
As an internet user: Fix 502 or bypass it
If you want to access a page and instead get the status code 502, there’s a high chance that the error isn’t with you. In most cases, it can be fixed by simply reloading the page. If the problem is solved by doing that, then it means that the server was just temporarily overloaded. Since such failures can also last for a fairly long time, reloading the page again is only really worth it after 15 minutes. Still receiving the same error message? Then clear your cache and cookies, as it could be that your browser didn’t truly reload the page and instead just accessed data from your internal storage (you don’t necessarily have to delete all of your cookies. Within your browser, you can display all of the cookies and remove only those that have something to do with the corresponding website.)
If the error is actually on the server side but you still want to access the content right away, there are also other ways to bypass the error message. This relies on the Google cache. Google saves websites for a time on its own servers and so can display an earlier version of the respective website. To load the cache page of the search engine, enter cache: in the search field and then the URL that you would like to visit (for example, cache:https://facebook.com). You should be aware, though, that you’re viewing an outdated version of the site. If you need to go back through the site’s history to find a working version, then the Wayback machine — from the nonprofit internet archive — can help. Various versions from the past years are stored here.
The error could also be in your system — even if the status code indicates something else. To check whether the error stems from other users or you, you can, for example, use the web service Down for everyone or just me?. Of course, if you can’t access any websites without the “Bad Gateway” message, then it’s obvious that the error has something to do with your computer, browser, or firewall. If the error is actually only occurring for you, then check the functionality of your browser. The first step should be restarting the browser. If this doesn’t work, then start your browser in safe mode. In safe mode, the browser deactivates any installed plugins. This allows you to check if a browser extension is the source of the error message.
To do this, you need to open the command line of your operating system (for Windows, this is the Command Prompt, for Mac, the terminal). First, locate the file to run the browser, and then type the complete path in quotation marks in the command line. Every browser manufacturer has a different command for starting the safe mode:
- Firefox: “C:\Program Files\Mozilla Firefox\firefox.exe” -safe-mode
- Internet Explorer: “C:\Program Files\Internet Explorer\iexplore.exe” -extoff
- Chrome: Google’s browser doesn’t offer a safe mode. If you instead switch to incognito, all extensions will be deactivated.
You can also use something other than your standard browser. If this is successful, then it’s recommended to uninstall and reinstall your current standard browser. If switching browsers doesn’t solve the problem with the bad gateway error, then it’s time to check your network settings. The simplest option here is to restart your modem and router. If this isn’t successful, then try to switch from Wi-Fi to LAN and use a cable connection.
Sometimes, the error isn’t with you or the website operator, but instead the “502 Bad Gateway” error is the internet provider’s fault. The cause would then be a false entry on their DNS server. To bypass the error message, enter a different DNS server into your settings. On Windows, this can be changed in your TCP/IP connection settings. For testing purposes, you can access Google’s free DNS server, for example, at 184.108.40.206 and 220.127.116.11.
If the error isn’t caused by the webmaster, there’s not much left for you to do other than wait (or use a cached version). In most cases, the error is temporary and is already being tackled by the webmaster. For smaller sites, it could also be helpful to take the initiative and contact the operator of the website. It could be that they don’t know about the disruption yet and will appreciate your heads-up.
As a webmaster: Examine the website
A visitor to your website has shared with you that they’re seeing the error message 502 when they try to access your website. What does that mean for you? Just as for the surfing visitor, it’s not always clear to the webmaster at first glance where the error lies. First, you need to check whether your website is still accessible in general. If your server is truly failing, you should contact your hosting provider. Maybe they already know about the error and their IT team is working on a solution. You should also check the log files of your server for error messages. PHP programming in particular can often be the source of errors, so definitely check if your error source is either there or in your database. If necessary, you could use an old backup to quickly remedy the failure.
Oftentimes, the error only occurs because the server was temporarily overloaded or took too long to provide a response to the upstream server. If such overloads start occurring more frequently, you should contact your hosting provider. Together, you can achieve a better configuration for your webserver so that it doesn’t fall to its knees at peak times. But in some cases, it’s the communication between the different webservers that isn’t running smoothly. Then you should check whether your firewall is correctly set up and make sure that it’s not blocking any legitimate queries. Another source of error could be that the name resolution isn’t functioning properly. Check your name server settings with your hosting provider (for IONOS users, this takes place via the customer login. There you need to select the appropriate domain and switch to DNS settings).
If you should encounter a server failure that you can’t fix within a few minutes, then you should be sure to use your social media channels to inform the visitors of your website.