Cloudflare is a massive Content Delivery Network (CDN) and security service that sits between a website's visitors and its origin hosting server. When communication between Cloudflare's edge servers and the website's origin server breaks down, Cloudflare displays custom 5xx error pages instead of the requested website.
If you encounter one of these errors, understanding what the code means can help you locate the root cause and restore connectivity. In this guide, we break down the four most common Cloudflare errors and how to resolve them.
1. Error 520: Web Server Returned an Unknown Error
Cloudflare returns an Error 520 when the origin web server sends an empty, invalid, or unexpected response back to Cloudflare's request proxy.
- Common Causes: Web server crashes (like Apache or Nginx processes restarting), origin firewall blocking Cloudflare IPs, or headers exceeding size limits.
- How to Fix (As a Webmaster): Inspect server crash logs, check if web server processes are stable, and examine header sizes. Make sure your Web Application Firewall (WAF) permits Cloudflare's IP ranges.
2. Error 521: Web Server Is Down
An Error 521 occurs when the origin server refuses the connection from Cloudflare. Instead of receiving a response, Cloudflare cannot connect to the server at all on port 80 or 443.
- Common Causes: The origin web server is offline, crashed, or its local firewall is actively blocking Cloudflare's proxy servers because it mistook the high volume of proxy requests for a DDoS attack.
- How to Fix (As a Webmaster): Verify that your web service (Apache/Nginx/IIS) is active and running. Ensure that fail2ban, iptables, or local firewalls are configured to whitelist all Cloudflare IP addresses.
3. Error 522: Connection Timed Out
An Error 522 is returned when Cloudflare cannot establish a TCP handshake with the origin server before the connection times out. This means the server is taking too long to acknowledge the request.
- Common Causes: Server overload (running out of memory or CPU bandwidth to accept new connections), routing issues between Cloudflare and your host, or firewall dropping the connection packets instead of rejecting them.
- How to Fix (As a Webmaster): Monitor your server resource limits (CPU/RAM). Check network routing tables and confirm that no software firewall is rate-limiting Cloudflare IPs.
4. Error 524: A Timeout Occurred
Unlike Error 522, an Error 524 means Cloudflare successfully connected and sent the request, but the origin server failed to return a response before the default 100-second timeout window expired.
- Common Causes: A database query is taking too long, a background PHP script is processing large datasets, or the server is running an intensive operation that blocks HTTP responses.
- How to Fix (As a Webmaster): Optimize database indexes, refactor heavy tasks to run asynchronously via background jobs or cron queues, and optimize PHP script performance.
Troubleshooting for Website Visitors
If you are a regular visitor seeing these errors, remember that 99% of Cloudflare 5xx errors are server-side issues that can only be resolved by the site owner. However, you can try these client-side steps:
- Force Refresh: Press
Ctrl + F5to force a live reload. The server might have had a split-second slowdown and will load normally now. - Clear DNS Cache: Follow our DNS Troubleshooting guide to clear DNS records, as your device might be resolving to a bad local CDN node.
- Disable VPN: Sometimes your VPN route to the CDN edge server is experiencing latency, causing timeouts. Disabling or switching VPN locations can bypass this.