What is a 502 bad gateway and how do you fix it?

What does this networking error mean for users and website owners?

When it comes to broken webpages, 502, 503, 504 and 500 errors are perhaps the most difficult for a user to solve. All of these error codes refer to problems happening at the server end of a connection, and tend to be overly cryptic in what is actually going wrong.

Here we're going to look specifically at the 502 bad gateway error, which is one that most internet users will have encountered at some stage. The good news is that a 502 error is not caused by something going awry with your own equipment or internet connection. Unfortunately, that makes it a little more difficult to fix.

Referred to as an HTTP Status Code, this error indicates to web admins that something has been incorrectly configured on the server. However, there are multiple potential causes of a 502 error and so solving it can be a time-consuming process. What you can ascertain straight away, however, is that a 502 error is related to a communication problem between a gateway or proxy server, and the upstream or origin server.

Below we've pulled together some of the more common reasons for a 502 error, and some potential fixes.

Causes of a 502 Bad Gateway error

Server overload: An error may appear if the website's server has exceeded its operational memory capacity and has overloaded, which is normally associated with an unexpectedly high number of visitors trying to connect to the site - such as a DDoS attack.

Advertisement
Advertisement - Article continues below

Request blocked by a firewall: Firewalls are an essential part of any cyber security policy, however, they can be overzealous determining whether server communication is malicious. This is often a problem with DDoS protection systems, which can block server requests from a content delivery system and cause the network to grind to a halt.

Server overload: A server can crash if it has exhausted its memory, due to a multitude of visitors on site or a DDOS attack.

Firewall blocks a request: A firewall may block communications between an edge server and upstream server. Some DDoS protection systems can over-react and block requests from a content delivery system.

Faulty programming: Sometimes an error in a website's code may mean that requests cannot be answered correctly, prompting this error to show up.

Network errors: DNS issues, routing problems, and ISP related issues can also lead to a 502 Bad Gateway error.

Server software timeouts: This error can also occur when a web server takes more time to complete and a caching tool reaches its timeout values that time. Slow queries can also cause this problem too.

How to fix a 502 Bad Gateway error

Usually, these errors will go away by themselves and refreshing a web browser page may be all that is needed to get the page you were looking for. If this happens, then the problem was a temporarily overloaded server.

Should it continue to happen, using a web service such as Down for everyone or just me? will tell you if the problem is more widespread. Use of a third-party proxy such as Hide My Ass can sometimes eliminate problems with a particular ISP (maybe the ISP blocks access to a particular website).

If this error happens regularly, it may require some further investigation in order to find a solution. Examining web server logs at the time of the error occurring will be a good place to start. If you are the owner of the website, you can check your FQDN (fully qualified domain name) is correctly resolving. You can also check a server is reachable via a ping text or traceroute.

Featured Resources

The IT Pro guide to Windows 10 migration

Everything you need to know for a successful transition

Download now

Managing security risk and compliance in a challenging landscape

How key technology partners grow with your organisation

Download now

Software-defined storage for dummies

Control storage costs, eliminate storage bottlenecks and solve storage management challenges

Download now

6 best practices for escaping ransomware

A complete guide to tackling ransomware attacks

Download now
Advertisement

Most Popular

Visit/security/identity-and-access-management-iam/354289/44-million-microsoft-customers-found-using
identity and access management (IAM)

44 million Microsoft customers found using compromised passwords

6 Dec 2019
Visit/cloud/microsoft-azure/354230/microsoft-not-amazon-is-going-to-win-the-cloud-wars
Microsoft Azure

Microsoft, not Amazon, is going to win the cloud wars

30 Nov 2019
Visit/hardware/354237/five-signs-that-its-time-to-retire-it-kit
Sponsored

Five signs that it’s time to retire IT kit

29 Nov 2019
Visit/business/business-strategy/354195/where-modernisation-and-sustainability-meet-a-tale-of-two
Sponsored

Where modernisation and sustainability meet: A tale of two benefits

25 Nov 2019