Some links on this page are affiliate links. If you sign up through one, Rigcheck may earn a commission at no cost to you. It doesn't change what this guide recommends. How we handle this.
Your site sits behind Cloudflare and visitors see a Cloudflare error page with a code in the 520s. Cloudflare itself is working: these pages mean it reached out to your server (the origin) and didn't get a usable answer. The error page shows this as a diagram with your host marked "Error".
The four common codes fail at different moments, so the number tells you where to look:
| Code | What happened | Check first |
|---|---|---|
| 521 Web server is down | Your server refused the connection. | Is the web server running? Is a firewall blocking Cloudflare? |
| 522 Connection timed out | Your server never answered the connection attempt, or stopped answering partway. | Firewall dropping Cloudflare, an overloaded server, or the wrong IP address in Cloudflare DNS. |
| 524 A timeout occurred | Your server accepted the request but took too long to send a response. | Slow pages, long-running scripts, an overloaded server. |
| 520 Web server returns an unknown error | Your server answered with something empty or broken. | Crashes, oversized headers or cookies, HTTP/2 problems. |
The order of a connection explains the codes: Cloudflare connects (521 if refused, 522 if there's no answer), sends the request, then waits for a reply (524 if it's too slow, 520 if it's garbled).
Before you start: confirm it's your server
These codes come from Cloudflare, so a quick test from outside tells you which one you have right now. From any computer:
curl -sI https://yourdomain.com/ | grep -i -E "^HTTP|cf-error-type|cf-ray"Cloudflare-generated error pages carry a cf-error-type header (added in 2026; as of November 2026 its value is 52x for these errors), which proves the error came from Cloudflare rather than being passed through from your server. Keep the cf-ray value: your host or Cloudflare support will ask for it, along with the time and the full URL.
Then test your server without Cloudflare in the way. Find its IP address (your hosting dashboard shows it, and it should match the A record in Cloudflare DNS), and run:
curl -v --resolve yourdomain.com:443:203.0.113.10 https://yourdomain.com/Replace 203.0.113.10 with your server's IP. This sends the request straight to your server with the right hostname. If it fails too, the problem is your server. If it works, something is blocking or slowing down Cloudflare specifically, usually a firewall.
Error 521: web server is down
Cloudflare reached your server, and the server refused the connection. Cloudflare's own docs name the two usual causes: the web server isn't running, or something on the server is blocking Cloudflare.
- Check the web server is running. On a Linux server:
sudo systemctl status nginx(orapache2,httpd,caddy). If it's stopped, its log says why; start it again once that's fixed. - Check it listens on the right port. Cloudflare connects on port 443 when your SSL/TLS mode is Full or Full (strict), and on port 80 when it's Flexible.
sudo ss -tlnplists what's listening. A server with no HTTPS set up, behind a Full mode setting, refuses every connection on 443. - Allow Cloudflare's IP ranges. Firewalls, fail2ban and security plugins sometimes block Cloudflare's addresses, because every visitor appears to come from them. Allow every range on Cloudflare's published list at
cloudflare.com/ips.
Error 522: connection timed out
Cloudflare tried to connect and got no answer at all. As of November 2026, Cloudflare gives up after 19 seconds without a reply to its connection attempt, or after 90 seconds if the server stops acknowledging a request it has accepted.
- Check the IP address in Cloudflare DNS. If you moved hosts or your server's IP changed, the A or AAAA record in Cloudflare may still point at the old address, where nothing answers. Compare it with the IP in your hosting dashboard.
- Check for a firewall silently dropping Cloudflare. Cloudflare calls this the most common cause. A firewall that drops packets (instead of refusing them) produces a 522, not a 521. Allow all of Cloudflare's IP ranges, including in your host's network firewall or security group, not only on the server.
- Check the server isn't overloaded. A server that's out of memory or CPU can stop accepting new connections. Look at its load and memory, and at what your host's dashboard shows for the time of the errors.
Error 524: a timeout occurred
The connection worked and the server accepted the request, but no response arrived in time. As of November 2026, Cloudflare's default limit is 125 seconds (many older articles still say 100). On Enterprise plans it can be raised; on other plans it can't.
- Find the slow page. 524s usually hit one kind of request: a large export, a report, an import, a backup triggered from the browser. Your web server's access log, with response times turned on, shows which.
- Move long jobs out of the request. Instead of making the browser wait, start the job in the background and let the page check on its progress (Cloudflare calls this status polling). That's the real fix.
- Or take that part off Cloudflare. For admin tools that genuinely need to run long, Cloudflare suggests a separate subdomain set to DNS only (grey cloud), so requests to it skip the time limit.
- Check for an overloaded server. If every page is slow, not just one, the server is short of resources or something it depends on, often the database, is struggling.
Error 520: web server returns an unknown error
The server answered, but with something Cloudflare couldn't use: an empty reply, a connection closed mid-response, or a response that breaks the rules. Cloudflare's list of common causes:
- The app or web server crashed while answering. Check the server's error log around the time of the error; Cloudflare notes 520s are common with PHP applications that crash the web server.
- Response headers over 128 KB, usually from too many or too-large cookies. Clearing cookies in your browser making it go away is the clue.
- A broken HTTP/2 setup on your server. If your server says it supports HTTP/2 but doesn't handle it properly, Cloudflare gets a 520. You can test this by turning off HTTP/2 to Origin in the Cloudflare dashboard (under Speed, Settings, Protocol Optimization).
- A firewall or security plugin cutting Cloudflare off mid-response. The same IP allow-list fix as 521 and 522.
- Authenticated Origin Pulls turned on in Cloudflare without your server set up to accept Cloudflare's client certificate.
As a stopgap while you investigate, Cloudflare suggests setting the affected DNS record to DNS only, or pausing Cloudflare, so visitors reach your server directly. That also confirms whether the problem only happens through Cloudflare. Remember to switch it back.
Related codes
- 523, origin is unreachable: Cloudflare has no network route to your server's IP. Usually a wrong IP in Cloudflare DNS, or a routing problem at the host.
- 525 and 526: the connection worked but the HTTPS handshake to your server failed (525) or your server's certificate isn't valid (526). These are SSL problems: the SSL certificate checker shows what browsers see, and Cloudflare too many redirects covers the SSL mode settings. Cloudflare error 525 and 526 walks through both in detail.
- 502 and 504 with a plain page that names nginx or Apache came from a proxy on your own server, not from Cloudflare. 502 Bad Gateway covers that case.
After the fix
Load the site in a private window, run the curl -sI test again, and check that no cf-error-type header comes back. If your host fixed something, ask what it was: a firewall that blocked Cloudflare once can do it again after an update. To hear about the next outage before your visitors do, set up an uptime monitor.