One of the things that certainly frustrate both consumers and web owners is seeing an error code pop up on the website or on one of its pages. One of those annoying pests is the 502 error or bad gateway error.
Although not as common as other server errors, this one is particularly troublesome when it does occur, especially since it’s often difficult to find the root of the problem.
But, what is 502 bad gateway error exactly?
Simply put, this error is HTTP (Hypertext Transfer Protocol) status code and it occurs when one online server doesn’t get or thinks it didn’t get a proper response from another online server.
It can happen to anyone on any setup, any browser, and any device. Therefore, let’s see what causes this error and how to fix, and hopefully get rid of it for good.
The 5xx gang
As you may already know, the 502 is not the only error that can occur among the 500 series of errors that are just waiting to ruin your day. That said, here are a few of the most common and most important errors from the 500 group that you should be aware of.
- 500 Internal Server Error – Your web server will display this error once it encounters a condition that prevents it from fulfilling its task, i.e. client request.
- 501 Not Implemented – server cannot support or recognize the request method. It lacks the functionality to process the request so it responds with this error.
- 502 Bad Gateway – servers had a fight and now they’re not talking to each other. Jokes aside, while acting as a proxy or a gateway, your server didn’t receive a proper response from an upstream server while attempting to process the request.
- 503 Service Unavailable – A temporary condition when a server is unavailable to process requests because either there’s a maintenance happening or it’s currently overloaded.
- 504 Gateway Timeout – The server, while acting as a proxy or a gateway again didn’t get a response on time from another server, such as DNS, for instance, so it couldn’t process the request.
- 505 HTTP Version Not Supported – This error occurs when your web server cannot or will not support the version of the HTTP protocol version originating from the request. The error usually contains a description of why the server won’t cooperate.
The causes behind 502 Error
In most cases, the 502 error is just a hiccup in communication between two online servers. Nothing major and nothing too serious. However, finding out exactly what caused a 502 error can oftentimes be quite challenging.
The main reason is that this error occurs between two online servers you have absolutely no control over.
For web owners that are not developers themselves, having one on your team can be very helpful when dealing with such errors. You can check online for software engineer jobs to get a clear picture of what you might expect from a developer should you decide to hire one.
What’s more, this error may disguise itself as various other error messages, such as 502 Proxy Error, HTTP 502, 502 Bad Gateway NGINX and so on. In any event, before you lose your sanity over what might have caused the error, here are a few most common reasons behind it.
- The origin server is not working – Simply put, your server may not be working properly. The root of your problem may be a connectivity issue, server downtime, overload, too much traffic etc.
- Domain name issues – This problem occurs when the domain is not determining the IP address properly. Incorrect DNS records set as Domain hosting level may be the reason behind this issue. Also, the changes made to the DNS probably didn’t have enough time to propagate globally so the error occurs. This may be because of a slow TTL (Time To Live) factors.
- Request blocked by the Firewall – Ah yes, the good old firewall and its security concerns. When in doubt about the problem, check the firewall. In most cases, the mastermind behind the 502 error is, in fact, the firewall. It can block requests between serves, especially on WordPress websites that have security plugins. What’s more, it can also be the DDoS protection kicking in.
- Server failure – Your server kicked the bucket. There are several reasons this might occur. For instance, the server is offline due to maintenance, the server crashed or server content is in violation of the provider’s terms and conditions, go figure.
- Browser error – Believe it or not, oftentimes the reason behind our 502 are browser extensions. This is especially true when having AdBlock extensions that protect users from annoying ads and pop-ups. Another reason can simply be an outdated version of the browser in use.
Fixing the 502 error
Now we’re getting to the interesting part. Fixing a 502 error is quite often as simple as it gets. From a consumer point of view, this can be as effortless as reloading the page. There are several ways to fix this error and here are a few of them.
- Reload the page – Yes you read that right, just reload the page and the error may be gone for good. As mentioned before, the poor thing may just need a bit more time.
- Start a new browser session – Another fix is to close everything, clear browsing history, cookies and cache, and start a new session. A new private or incognito session may also help fix the error.
- Restart your computer – If it all fails, reset the machine and try anew.
- Try a different browser – The problem may be browser-related so try a different one, such as Google Chrome, Mozilla Firefox etc.
- Come back later – Things look pretty much hopeless if you tried all of the above to fix the error. You may try to contact your Internet service provider or the web master but then again, just go get yourself some coffee and come back later, the error may resolve itself by the time you get back.
Solution for the developers
The developer point of view differs from the consumer one. Fixing the 502 error as a web manager can also be seamless. Therefore, here are a few solutions to the 502 for developers.
- Try to figure out if the upstream server is reachable by trace-routing or ping testing the server’s IP.
- Use the DNS test tools to check if the qualified domain name is resolving properly.
- Check the server or website error logs to see if there’s a particular error being thrown at the server.
- For WordPress sites, try temporarily renaming the “wp-content/plugins” folder to rule out the plugins as a possible cause for the error.
- Check the firewall logs for any signs of blocks.
Among all the possible errors that might occur on the server or on the website, the 502 bad gateway error isn’t the worst of the lot. However, it’s still troublesome nonetheless. Although it may be resolved quickly and efficiently, it may point out to more serious underlying issues that may cause more serious problems in the future, which is why it’s worth checking out a bit further when it does occur.