Bad gateway errors: Why they happen and 5 solutions

Updated: August 31, 2026 Time to read: ~

TL;DR

A 502 Bad Gateway error occurs when a proxy or gateway server receives an invalid response from an upstream origin server. Governed by HTTP status codes defined by the IETF, this error can stem from DNS misconfigurations, server overload, or firewall connectivity issues. Both developers and end users have actionable steps to diagnose and resolve it quickly.

Understanding the 502 Bad Gateway error

You attempt to load a website, and this message flashes on your screen: 502 bad gateway.

What does it mean?

A 502 bad gateway message indicates that one server got an invalid response from another. In essence, you've connected with some kind of interim device (like an edge server) that should fetch all of the bits you need to load the page. Something about that process went wrong, and the message indicates the problem.

Let's dig deeper into the 502 bad gateway meaning, and we'll offer five solutions you can try to fix the problem.

What does '502 bad gateway' mean?

The hypertext transfer protocol (HTTP), a set of rules that regulate the web released by the Internet Engineering Task Force (IETF), governs every internet transaction. In the HTTP system, problems have numbers.

The 502 status code, per IETF, indicates a few things:

  • Proxies: If you get a bad gateway note, you're working with a gateway or proxy server.

  • Connection: The proxy tried to work with the origin server.

  • Mistake: The proxy got some kind of invalid response from the server.

The numeric language may seem confusing, but it's actually quite efficient. One simple number tells you a great deal about why the page won't load.

How can you prevent and fix a 502 bad gateway error?

No one wants to deal with error codes while surfing the web. And as a developer, mistakes like this can shift your traffic and impair your reach. Fixing the problem quickly should be your top priority.

502 gateway errors often stem from:

  • Domain Name System (DNS). Computers do a quick lookup to resolve a numeric IP to a standard format. If that system goes wrong (as it would if you switched to a new hosting service), a bad gateway warning appears.

  • Traffic. Too many visitors can overwhelm a server and make requests impossible to resolve.

  • Connectivity. Firewall setup problems can block proxy communication.

As a developer, you can solve these issues by:

  • Assessing. Are you dealing with a Domain Name System (DNS) problem? Or are you overwhelmed by traffic? You'll know what vendor to call next.

  • Testing. Use a ping or traceroute to determine if your server is even accessible.

  • Balancing. You could scale back firewalls and otherwise ensure all traffic reaches you. But this comes with major security risks. Know what you're getting into.

As a visitor, you can:

  • Reload. Simple traffic problems may fade if you wait a moment and try the site again.

  • Clear. Your browser cache can interfere with smooth surfing. Dump the data and try again.

Error 502 is just one type of HTTP error your website might generate. Read up on another common problem, Error 431, on our blog.

Frequently asked questions

What triggers a 502 bad gateway error?

A 502 bad gateway error is typically triggered by DNS misconfigurations (such as switching to a new hosting service), server overload from too many visitors, or firewall setup problems that block communication between the proxy and the origin server.

What is the difference between a gateway and a proxy server in the context of a 502 error?

In the context of a 502 error, both gateways and proxy servers act as interim devices between you and the origin server. Per the IETF's HTTP status code definition, a 502 error means the gateway or proxy server received an invalid response from the upstream origin server it was attempting to reach on your behalf.

How can a developer diagnose a 502 bad gateway error?

A developer can start by assessing whether the issue stems from a DNS problem or traffic overload to determine which vendor to contact. They can then use a ping or traceroute to check whether the server is accessible. If needed, they can also review firewall settings to ensure traffic is reaching the server, keeping security risks in mind.

What can a website visitor do when they see a 502 bad gateway error?

A website visitor can try reloading the page after a brief wait, as simple traffic problems may resolve on their own. They can also clear their browser cache, which can sometimes interfere with smooth surfing, and then attempt to load the page again.

Can adjusting firewall settings fix a 502 error, and what are the risks?

Yes, scaling back firewall settings can help ensure all traffic reaches the server and may resolve a 502 error caused by blocked proxy communication. However, this comes with major security risks, so it is important to fully understand the implications before making such changes.

What HTTP standard governs 502 bad gateway errors?

502 bad gateway errors are governed by the hypertext transfer protocol (HTTP), specifically the rules defined by the Internet Engineering Task Force (IETF). The 502 status code is documented in the IETF's HTTP/1.1 specification and indicates that a gateway or proxy received an invalid response from an upstream server.

References

Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content. (June 2014). Internet Engineering Task Force.

Continue your Identity journey