How to Solve 502 Bad Gateway Issues?
502 Bad Gateway mean?
502 Bad Gateway indicates that the edge server (server acting as a proxy) was not able to get a valid or any response from the origin server (also called upstream server). This can occur for a few reasons, which we'll discuss in the section below. If one of KeyCDN's edge servers receive a
502 Bad Gateway response from your origin server, KeyCDN will return a
500 Origin Not Reachable page. To get a better understanding on how KeyCDN handles certain error codes, check out our CDN Error Codes page.
What are the reasons for
502 Bad Gateway responses?
There are three main culprits that cause
502 Bad Gateway responses. These include:
- Domain name not resolvable: The domain name is not resolving to the correct IP or it does not resolve to any IP. It is important to note that DNS changes could take same time until they are global fully propagated and active. This is dependant on the TTL, or time to live, defined per record.
- Origin server down: The server is not reachable, either because it is down or there is no connectivity to the server given.
- Firewall blocks request: A firewall blocks the communication between the edge servers and the origin server. This can also be caused by security plugins of your CMS. Some DDoS protection and mitigation systems might are too overreactive and start blocking requests from our content delivery servers.
How you might see a
502 Bad Gateway error
Based on your web server, you might see a different
These all mean the same thing, it is only their naming conventions that differ. Here are a few examples of what you might see:
- 502 Bad Gateway
- HTTP Error 502 - Bad Gateway
- 502 Service Temporarily Overloaded
- Error 502
- 502 Proxy Error
- HTTP 502
- 502 Bad Gateway NGINX
You can see in greater detail what the error specifically entails by going to your web server's error log file. All error and diagnostic information is stored in this file making it a valuable resource to check when you need more details about a particular error. You can locate this file in Apache by going to
/var/log/apache2/error.log and in Nginx by going to
How to solve
502 errors as a web developer
As a web developer or owner of the website, there are a few reasons why you may be experiencing a
502 Bad Gateway error on your origin server. Therefore, you may need to try various methods to resolve the issue. Reference the list of suggestions below:
- Check if your FQDN (fully qualified domain name) is resolving correctly by using our DNS test tool.
- Verify if your server is reachable by using a ping test or traceroute.
- Check your firewall logs if you are seeing unusual drops.
- If you're a Cloudflare user, try disabling it as once you've reached a certain limit Cloudflare will return a
502 Bad Gatewayerror to your visitors.
How to solve
502 errors as a visitor
If you're a website visitor and experience a
502 Bad Gateway error then there is also a few things you can try to resolve it. Although the primary issue will almost always be the responsibility of the web developer, visitors can try the following:
- Perform a hard refresh in your browser. On Macs, this is done by pressing
- Clear your browser cache and delete cookies. Your browser may be holding on to certain files that were saved once you visited the website with a
- Restart your computer/networking equipment
- Change your DNS servers. If you've never changed them in the past you likely still have the default servers assigned to you by your ISP, try using open DNS servers such as Google's Public DNS.