How Can I Solve 502 Error Bad Gateway from Cloudflare?
By Jithin on August 17th, 2018
502 Bad Gateway means our network is not able to connect with your server for communication. The 502 Bad Gateway error is an HTTP status code which indicates that one server on the internet received an invalid response from another server.
In some cases, this error is returned by Cloudflare before contacting your origin server, and in that case, the error page should be like this.
The name “cloudflare-nginx” appears at the bottom of the error message indicating that the error is coming from Cloudflare. If you do not see this, this error is “not” coming from Cloudflare, and it is coming from origin server which looks like given below.
How the 502 Error Appears
Different web servers do show this error differently because this error can be customized by each website. Here are some common ways you might see it.
#502 Bad Gateway
# 502 Server Error: The server encountered a temporary error and could not complete your request.
#Temporary Error (502)
#502 Service Temporarily Overloaded
# HTTP Error 502 – Bad Gateway
#Bad Gateway: The proxy server received an invalid response from an upstream server
#502 Proxy Error
Cause of 502 Bad Gateway Errors
1) Domain name not resolvable
The domain name is not pointing to the correct IP or it does not point to any IP this problem may happen. Also, DNS propagation could take some time to make changes in DNS setting. It may take 24 to 48 hours to make reflect which is dependent upon the TTL defined per record on the DNS.
The origin server is not reachable, this may due to the server is down for some reason or there is no communication to the server given.
3) Firewall blocks
A firewall interrupts the communication between the edge servers and the origin server. This may be caused by security plugins of your CMS.As a part of DDOS protection and mitigation process or due to some strict firewall rules servers can be blocked from accessing the original server.
What to do after getting 502 Bad Gateway error
1)If you got 502 bad gateway error you should check your IP address in the zone management, click on setting and make sure that the given IP is correct or not. If the IP address incorrectly, you need to update the origin IP in the Pull Zone Configuration to match the new IP, clear your zone cache. This should fix the problem.
2) By using a ping test or trace-route, verify if your server is reachable or not.
3) If the IP address is correct to check your firewall rules if you are seeing unusual drops.
Errors Like 502 Bad Gateway
Error messages are related to the “502 Bad Gateway error” is given below:
500 Internal Server Error
503 Service Unavailable
504 Gateway Timeout
If you need any further help please do reach our support department.