Troubleshooting Cloudflare & Web Server HTTP Errors
Demystifying Cloudflare 5xx Gateway Errors
When your website sits behind a reverse proxy like Cloudflare, specific 5xx status codes indicate exact failure points between the edge proxy and your origin web server:
- Error 521 (Web Server Is Down): Cloudflare edge servers could not establish a TCP connection because your origin server (Nginx/Apache) is offline or blocking Cloudflare IP addresses.
- Error 522 (Connection Timed Out): The TCP handshake between Cloudflare and your origin server timed out before completion.
- Error 502 (Bad Gateway): The origin server returned an invalid HTTP response.
❓ Frequently Asked Questions
How do I fix Cloudflare Error 521?
Verify that your origin web server (e.g. Nginx, Apache) is actively running, and ensure your origin firewall (UFW, iptables) whitelists Cloudflare's published IP ranges.