How to fix a 502 error

502 bad gateway error: What it is and how to fix it

A 502 bad gateway error is one of the most common error codes you’re likely to see when a web page won’t load. This could be due to DNS issues, geo-restrictions, or other issues discussed in this article, where we explain what the error means and explore possible ways to fix it. Please be aware, however, that as a server-side problem, the only solution may be to simply wait until the website owner fixes the issue. 

I this article, we’ll look at:

What does “502 bad gateway” mean?

A 502 bad gateway error occurs when you connect to a website via an intermediary server, such as a gateway(yeni pencere), load balancer(yeni pencere), CDN(yeni pencere), or reverse proxy server. It means you connected to the intermediary server without issue, but the intermediary server couldn’t connect to the destination server that hosts the website you’re trying to connect to.

Bad gateway error from Cloudflare

Because so many websites rely on Cloudflare’s reverse proxy servers for content delivery and DDoS protection, Cloudflare’s 502 error page is one of the most commonly encountered. It also provides an unusually useful visual representation of the problem. 

The 502 bad gateway error is an HTTP status code(yeni pencere), as defined in Section 6.6.3 of the RFC 7231(yeni pencere) specification. How the error is displayed is determined by whoever runs the intermediary server that returns it.

502 error from Google

Common variations include:

  • 502 Bad Gateway
  • 502 Service Temporarily Overloaded
  • Bad Gateway: The proxy server received an invalid response from an upstream server
  • Error 502
  • HTTP Error 502 – Bad Gateway
  • Temporary Error (502)
  • 502 Proxy Error
  • HTTP 502
  • 502 Server Error: The server encountered a temporary error and could not complete your request
  • HTTP 502
  • 502. That’s an error
  • Bad Gateway: The proxy server received an invalid response from an upstream server

What the error doesn’t explain is what caused it.

What causes a 502 bad gateway error?

A 502 error indicates that an intermediary server can’t connect to the destination (“upstream”) server. Common reasons for this include:

The destination server is overloaded

When a server receives too many requests at once, it may become overwhelmed and fail to respond to requests from other servers, leading to a 502 error for the end user. Servers can become overloaded due to sudden traffic spikes, insufficient server resources, or poorly optimized applications that use excessive resources.

Network issues between servers

A 502 error can occur if there are network connectivity issues between the intermediary server and the upstream server. Common network issues include packet loss and misconfigured routes (it could also include firewall issues, but we’ll discuss these separately below).

Poor connectivity between servers may also be the result of geo-restrictions or latency issues, especially if servers are located in different regions, or if there are intermittent internet issues affecting one of the servers.

Firewalls and other security restrictions

Firewalls or security software can mistakenly block legitimate requests from reaching a server. For example, if a firewall rule wrongly identifies certain traffic as suspicious, it may prevent the intermediary server from reaching the upstream server.

This issue can also arise if a CDN or proxy service tries to access a server that has strict security settings, such as whitelisting specific IP addresses or blocking certain regions.

DNS issues

If there’s a problem with DNS resolution, the proxy server may be unable to locate the IP address(yeni pencere) of the upstream server, leading to a 502 error. This can occur if DNS records are outdated or incorrectly configured. DNS issues might also happen during DNS propagation after a change in the destination server’s DNS settings, when some servers haven’t yet updated their records to reflect the new IP address.

Learn more about how DNS works

A misconfigured server

Server misconfigurations on either the intermediary or target server can result in 502 errors. Examples include incorrect server routing rules, broken reverse proxy settings, or an incorrect IP address or port specified for connecting to the upstream server.

This can also occur if there is a mistake in server software configuration files, or if a server is configured to only respond to requests from certain IP addresses.

Application errors and crashes

Sometimes, an application on the target server encounters an error or crashes, which prevents it from responding to the proxy server’s request. For instance, if a web application’s code is buggy, poorly optimized, or improperly maintained, it could cause the application to fail intermittently. Outdated software, database connection errors, and incompatible updates can also contribute to these application-level failures.

Timeouts

A timeout occurs when a server takes too long to respond to a request. The intermediary server may wait for a specified period (its timeout limit) before deciding that the upstream server isn’t responding. If this happens, the proxy server may respond with a 502 Bad Gateway error to indicate that the upstream server timed out.

Server maintenance or downtime

The target server may simply be offline (“down”). Undergoing maintenance is a common reason for this, and many websites display maintenance pages during scheduled downtime. 

However, other reasons include catastrophic server failure (the server has crashed), or the server has been forcibly shut down (for example, by the police or due to legal pressure over copyright issues). Sometimes websites are simply abandoned by developers no longer interested in maintaining them. 

Can I do anything to fix a 502 bad gateway error?

The fact that you can successfully connect to the intermediary server that’s showing you the 502 error strongly suggests there isn’t an issue at your end. This means that, in most cases, it’s up to the website owner to fix the issue. Chances are that if you wait a short time and then refresh the page in your browser, the issue will be resolved and you’ll be able to connect. 

If the problem persists, you can use online services such as www.isitdownrightnow.com(yeni pencere) to see if the site is working for others.

Check with third-party services to see if the web page is working for others

If it’s not, there’s not much you can do except maybe try to contact the website owners to find out what’s going on. If it is, the problem may indeed be at your end. Some things you can to try to resolve this are:

  • Clear your browser cache and cookies, as old or corrupt data stored by your browser can cause issues
  • Try another browser(yeni pencere), as this helps rule out browser-specific issues.
  • Restart your computer or mobile device, your modem, and your router (which are often the same device) to refresh your connection
  • Flush your DNS cache and check your DNS settings to ensure they’re correctly configured
  • If using a VPN (including Proton VPN), change VPN server. If that doesn’t work, try turning the VPN off. If the issue only occurs when using Proton VPN, please contact our support team
  • Conversely, if you’re not using a VPN, try using one. If you’re using Proton VPN, ensure that alternative routing(yeni pencere) is turned on in the app settings, as this unique anti-censorship feature is designed to bypass blocks by routing blocked connections through third-party networks

And remember to reload the site you are trying to access after each step you take to fix the issue. 

Don’t panic!

The 502 bad gateway error is almost always a server-side issue, meaning there’s probably nothing wrong with your connection. In all likelihood, a little patience while the website owner resolves the problem at their end, followed by refreshing the webpage, will resolve the issue. 

İlgili makaleler

Watch Thanksgiving Day football with Proton VPN
en
Here's how you can live stream this year's Thanksgiving football games using Proton VPN, whether you're watching from home or abroad.
Where to watch Macy's Thanksgiving day parade
en
Here's how and where to watch Macy's Thanksgiving Day Parade live from anywhere in the world with Proton VPN.
What we've been up to, and what's next
en
Here are the main things Proton VPN delivered this spring and summer and the exciting changes that lie ahead on our product roadmap this winter.
Proton VPN for Windows ARM
en
  • Proton VPN haberleri
We’re pleased to announce a new Proton VPN app with native support for Windows devices that use the ARM chipset.
What is doxing and is doxing illegal
en
  • Gizliliğin temel prensipleri
We look at what doxing is, who does it (and why), and at how to protect yourself from doxing .
Stream securely on tvOS with Proton VPN
en
With the Proton VPN Apple TV app, you can easily and securely watch your favorite content on your big-screen TV no matter where you are.