This article covers methods to resolve Cloudflare 502 error. Basically, the Cloudflare 502 error triggers when the origin web server responds with a standard HTTP 502 bad gateway or 504 gateway timeout error.
This happens due to firewall restrictions and server resource issues.
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.
2. server down
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.