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

502 bad gateway error spelt out in wooden blocks on a grey background to answer what is 502 bad gateway
(Image credit: Getty Images)

A 502 Bad Gateway is a common error message users can encounter while browsing the web. It's a frustrating message to run into, as it's usually impossible to tell what has caused the issue or what you can do to fix it.

The 502 Bad Gateway is one of a number of error codes that can appear, preventing users from accessing content across that particular domain.

What does a 502 Bad Gateway error mean?

An Error 502 Bad Gateway appears when a browser is unable to connect to a website's host server, blocking access to content across that particular domain. This type of error will not be unique to one user, and instead will be appearing for anyone trying to access the website's content.

You can quickly check if there is a problem with your own PC or device by visiting a completely different website. If you can do this without any problems, then you can be assured that your connection is fine.

A 502 Bad Gateway error rarely lasts very long and is usually in the process of being solved by the site administrator by the time you see the error message. The ‘Error 502 Bad Gateway’ message has been around for many years, which means websites have become quite skillful at fixing them quickly.

Depending on the web server that's hosting the content you're trying to access, you may see additional letters or codes appear alongside an 502 Bad Gateway message. For example, you might see '502 bad gateway nginx', if the website is making use of the Nginx open source platform to handle load balancing. However, functionally, the problem is the same regardless of the server being used.

What causes a 502 Bad Gateway error?

Server overload: An overloaded server is one of the most common causes of a 502 error. This is where the server has reached its memory capacity, often activated by an unusually high number of visitors trying to access the same website. This can just be a coincidence or driven by a big event, but it can also be a targeted DDoS attack.

RELATED RESOURCE

Whitepaper cover with two colleagues looking at papers with a laptop in front of them

(Image credit: Dell Technollogies)

Harness the power of technology to drive your business forward

Supporting your innovation projects with integrated as-a-Service models

DOWNLOAD FOR FREE

Request blocked by a firewall: With cyber criminals finding more and more ways to breach corporate networks, firewalls continue to play a key role in stopping them in their tracks. However, several firewalls can often go further than you’d like and inadvertently treat a massive influx of legitimate users as an attempted cyber attack. This can often occur with DDoS protection layers, which block requests from content delivery systems and cause the network to stop slowly.

Faulty programming: Often enough, a glitch or coding error in a website's code might result in requests not being answered correctly, sparking the 502 Bad Gateway error to show up.

Network errors: There is a multitude of potential networking errors that may occur, including potential DNS issues, routing problems, as well as issues relating to your Internet Service Provider (ISP). An ISP, for example, may have decided to block a certain web address.

Server software timeouts: The error can also show for users when a web server takes longer than expected to return a request, and the caching tool reaches its time values. Slower queries can also cause this problem.

Fixes for a 502 Bad Gateway error

Disclaimer

There are a number of key steps that users can try to fix a 502 Bad Gateway error. However, it's important to note that because it's very likely the error is being caused by the website server, these solutions only work occasionally and should be thought of a last resort.

1. Refresh your browser

(Image: © Future)

It sounds too simple, but in some cases where the server is overloaded with requests, sending a few more requests by refreshing the browser a few times can sometimes help reset the connection between the device and server, allowing you to resume browsing.

2. Clear your browser’s cache

(Image: © Future)

If refreshing the browser a few times doesn’t work then clearing the browser’s cache may help. Major browsers will make this option easy to find within their respective settings menus and most will simply let you enter a query using a search field to find the option. The browser’s cache stores important information that can become corrupted over time, so clearing this and re-attempting to connect to the server may do the trick.

3. Temporarily disable your firewall

(Image: © Future)

Not for amateurs, this is one of the more controversial methods on this list. Firewalls should always be active since they help block malicious threats from reaching your device. But, if you’re sure the server is safe to visit, then successfully re-attempting to visit the site with the firewall disabled can indicate there is an issue with the firewall’s settings interfering with network connections. You can adjust the settings in the admin console of the firewall provider.

4. Check with monitoring sites

(Image: © Downdetector)

There are a few free websites you can use to determine if other users are also having the same issues as you. Sites such as Down Detector monitor most major websites and provide real-time reports as to whether other users can connect or not. If using one of these sites, it’s helpful to contribute by leaving a report of your own - most don’t even require a registered account to do so. Searching the website’s name on social media platforms such as Twitter can also indicate if others are struggling too.

5. Use a VPN

(Image: © Surfshark)

Choosing to re-route your internet traffic through a virtual private network (VPN) can be helpful in determining if your ISP is the issue with the connection to the site. Sometimes ISPs will block access to certain websites and if a VPN allows you to reach it, then it’s most likely being blocked by your provider. Contact their customer service team to remediate the problem in the long term.

6. Examine web server logs

If this error persists, it may require some further investigation 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.

How long does it take to fix a 502 Bad Gateway error?

Depending on the route cause for your 502 Bad Gateway error, it can take some time to resolve the issue. Many of the solutions such as a quick refresh of the browser, clearing of the cache, or turning on or off of a firewall or VPN can be done within minutes of the error message being displayed.

If you’re the owner of a website and have recently migrated your domain from one host to another, this can lead to a 502 Bad Gateway error. In this case it could take 24-48 hours for the error to be fixed.

Other causes for a 502 Bad Gateway error include faulty network equipment, which could be resolved quickly or require total overhaul of hardware. It’s impossible to attach a specific time frame to what could be a broad range of issues with equipment.

Rene Millman

Rene Millman is a freelance writer and broadcaster who covers cybersecurity, AI, IoT, and the cloud. He also works as a contributing analyst at GigaOm and has previously worked as an analyst for Gartner covering the infrastructure market. He has made numerous television appearances to give his views and expertise on technology trends and companies that affect and shape our lives. You can follow Rene Millman on Twitter.