What Does 502 Bad Gateway Mean?
A 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 3 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
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 / 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 – for Web Developers
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 trace-route.
- 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 Gateway error to your visitors.
How to Solve 502 Errors – for Visitors
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 Cmd + Shift + R.
- 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 502 error.
- 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.