Home/Blog/Cloudflare 521, 522, 524 Errors: Fixes (2026)

Cloudflare 521, 522, 524 Errors: Fixes (2026)

Cloud shield icon with a broken link to a server rack below, concept of CDN origin connection error

Your site sits behind Cloudflare and visitors see an orange error page: 521, 522, or 524. These three codes all mean one thing — Cloudflare (which is working fine) cannot get a proper answer from your origin server (your actual hosting). But each number fails at a different moment, and reading the number correctly saves you from troubleshooting the wrong layer. This 2026 guide’s Cloudflare 521, 522, 524 error fix explains each code and gives you the fixes in order.

What Causes Cloudflare 521, 522, and 524 Errors?

Cloudflare sits between visitors and your server. When the visitor→Cloudflare leg works but the Cloudflare→origin leg breaks, you get a 52x. Timing identifies the error: instant failure ≈ 521, ~15 seconds then failure ≈ 522, ~100+ seconds then failure ≈ 524.

  • 521 – Web server is down: Your origin actively refused the connection (TCP reset). The web server process (Apache/Nginx/LiteSpeed) is stopped, crashed, or a firewall is explicitly rejecting Cloudflare. Instant failure.
  • 522 – Connection timed out: Cloudflare tried to open a connection and got no answer at all within the timeout window (~15s). The server is not rejecting — it is silent. Causes: firewall silently dropping Cloudflare IPs (not allowlisted), overloaded origin, wrong origin IP in DNS after migration, or network/routing issues.
  • 524 – A timeout occurred: Cloudflare connected successfully, but your origin never finished the HTTP response before Cloudflare’s read timeout (default 120s). The handshake worked — the application is just too slow: heavy database query, long import/export, slow external API, bloated page builder page.

How to Fix Cloudflare 521, 522, and 524 Errors

Start with the universal tests, then the code-specific fixes:

  1. Check Cloudflare’s status and pause Cloudflare. First rule out a Cloudflare-side incident (cloudflarestatus.com). Then, in the Cloudflare dashboard → Overview → Advanced Actions → Pause Cloudflare on Site. Wait a few minutes and visit your site directly. If it loads, your origin is fine and the problem is in the Cloudflare→origin path. If it still fails, the problem is your origin server itself. More Cloudflare troubleshooting is on the KamiWeb blog.
  2. Fix 521: restart the web server and check the firewall. Verify Apache/Nginx/LiteSpeed is running (hosting panel or SSH). If it is running, your firewall is likely blocking Cloudflare: allowlist Cloudflare’s IP ranges (published at cloudflare.com/ips, including IPv6) in your server firewall, CSF, and any security plugin. Also confirm your hosting account is not suspended.
  3. Fix 522: allowlist Cloudflare IPs and check resources. This is the number-one 522 cause — a firewall silently dropping Cloudflare’s connections. Allowlist the Cloudflare IP ranges everywhere: server firewall, .htaccess deny rules, and security plugins (Wordfence, etc.). Then check CPU/RAM usage in your hosting panel — an overloaded origin cannot answer in time. Verify the A record in Cloudflare DNS points at the current origin IP (migrations leave stale IPs behind).

Glowing cloud shield reconnecting to an origin server with restored data flow, concept of fixing the connection

  1. Fix 524: find and speed up the slow request. Identify which URL is slow (check server access logs or time the page). Common culprits in WordPress: heavy backup/export plugins, huge database queries, slow external APIs, bloated page-builder pages. Optimize the query, break imports into chunks, enable page caching so the slow page is served statically, and raise PHP limits (max_execution_time, memory) as a stopgap. A 524 means the page works — it is just slower than Cloudflare’s 120-second patience.
  2. Test the origin directly with curl. Bypass Cloudflare: curl --resolve yourdomain.com:443:YOUR_ORIGIN_IP https://yourdomain.com/ -o /dev/null --max-time 10 (use the IP from your Cloudflare DNS record). “Connection refused” = 521 pattern (nothing listening). Timeout = 522 pattern (packets dropped). Slow 200 = 524 pattern (slow app). This test splits the problem in half.
  3. Check SSL mode and origin certificate. If the origin has no valid certificate on port 443 while Cloudflare is set to Full/Full (strict), connections fail. Either install a valid origin certificate (Cloudflare offers free origin certs) or temporarily drop to Flexible while you fix it — then return to Full (strict). Keep everyday utilities handy via the KamiWeb free tools.
  4. Emergency bypass: go DNS-only. If Cloudflare cannot reach the origin during a critical period and the origin is verified healthy, set the DNS record to DNS-Only (grey cloud) in the Cloudflare dashboard. Visitors go straight to the origin while you diagnose the proxy path. Also consider upgrading an underpowered origin — recurring 522/524 under normal traffic means the server is too small. Find solid foundations in our free WordPress plugins and themes library.

Conclusion

Cloudflare 52x errors are always about the origin: 521 = refused (restart server, unblock Cloudflare IPs), 522 = silent (allowlist Cloudflare IPs, check overload and DNS), 524 = slow (optimize the slow request, cache it). Pause Cloudflare to split the problem, test the origin directly with curl, and fix the layer the timing points to. For more free resources, start at the KamiWeb homepage.