HTTP Error Codes

522 Connection Timed Out

HTTP 522 (Cloudflare)

Cloudflare couldn't establish a TCP connection to your origin server within 15 seconds.

What It Means

522 is a Cloudflare-specific error code. It means Cloudflare tried to connect to your origin server but couldn't establish a connection at all. This is different from a timeout waiting for a response (that's 524).

What happens:
User → Cloudflare → [Connection attempt to Origin] → No response → 522

Common Causes

  • Origin server is down — Your server isn't running at all
  • Firewall blocking Cloudflare — Your server's firewall is blocking Cloudflare's IP ranges
  • Wrong origin IP in Cloudflare — DNS is pointing to the wrong server
  • Port not open — Web server not listening on port 80/443
  • Server overloaded — Can't accept new connections
  • Network routing issues — Path between Cloudflare and origin is broken

How to Debug

  1. Check if origin is running — Can you access it directly (bypassing Cloudflare)?
  2. Check firewall rules — Are Cloudflare IPs allowed?
  3. Verify Cloudflare DNS settings — Is the origin IP correct?
  4. Check web server status — Is Nginx/Apache running?
  5. Test from multiple locations — Is it a regional network issue?

Allow Cloudflare IPs

Cloudflare publishes their IP ranges. Your firewall must allow these:

# Get current Cloudflare IPs
curl https://www.cloudflare.com/ips-v4
curl https://www.cloudflare.com/ips-v6

# UFW example (Ubuntu)
for ip in $(curl -s https://www.cloudflare.com/ips-v4); do
    sudo ufw allow from $ip to any port 443
done

# iptables example
for ip in $(curl -s https://www.cloudflare.com/ips-v4); do
    iptables -A INPUT -p tcp -s $ip --dport 443 -j ACCEPT
done

Quick Checks

# Check if web server is running
systemctl status nginx
systemctl status apache2

# Check if ports are open
ss -tlnp | grep -E ':80|:443'
netstat -tlnp | grep -E ':80|:443'

# Test connection to your origin directly
curl -v http://your-origin-ip/
curl -vk https://your-origin-ip/

# Check Cloudflare DNS settings
dig +short your-domain.com

522 vs Other Cloudflare Errors

522 Connection timed out - couldn't connect at all
523 Origin unreachable - DNS points to nothing
524 Origin timeout - connected but response took >100s
525 SSL handshake failed - certificate issues

Prevention

  • Keep Cloudflare IPs allowlisted (they update their ranges occasionally)
  • Monitor your origin server directly, not just through Cloudflare
  • Set up health checks in Cloudflare load balancer
  • Use a failover origin if your primary goes down
  • Subscribe to Cloudflare status updates

How to Monitor for 522 Errors

Monitor your origin server directly (bypassing Cloudflare) with UptimeSignal to catch outages before users see 522 errors. Also monitor the Cloudflare-fronted URL to detect CDN-layer issues. This dual approach pinpoints whether problems are at the origin or the proxy. See also: 504 Gateway Timeout, Connection Timeout.

Frequently Asked Questions

What causes a 522 Connection Timed Out error?
A 522 is Cloudflare-specific: Cloudflare couldn't establish a TCP connection to your origin server within 15 seconds. Causes: origin server is down, firewall blocking Cloudflare IPs, server overloaded, wrong origin IP in Cloudflare DNS, or network issues between Cloudflare and your hosting provider.
How do I fix a 522 error?
Verify your origin server is running. Whitelist all Cloudflare IP ranges in your firewall. Confirm the origin IP in Cloudflare DNS settings. Ensure your web server listens on ports 80/443. Check server resources with htop.
What is the difference between 522 and 524 errors?
522 = Cloudflare couldn't connect to your origin (TCP handshake failed -- origin is unreachable). 524 = Cloudflare connected but origin didn't respond within 100 seconds (read timeout -- origin is too slow). 522 is a connectivity problem; 524 is a performance problem. Check firewall for 522, check app performance for 524.
How do I whitelist Cloudflare IPs?
Get IPs from cloudflare.com/ips. For UFW: ufw allow from CIDR to any port 443. For iptables: -A INPUT -s CIDR -p tcp --dport 443 -j ACCEPT. Update regularly as Cloudflare adds new ranges. Consider Authenticated Origin Pulls for additional security.
Is a 522 error caused by Cloudflare or my server?
Almost always your server or the network path to it. Cloudflare is trying to connect and failing. Test by accessing your origin directly (bypassing Cloudflare): curl -v https://your-origin-ip. If it works directly but fails through Cloudflare, check your firewall allows Cloudflare IPs.

Monitor for connection timeout errors

UptimeSignal detects 522 and other connection errors instantly so you can respond fast.

25 monitors free, unlimited for $15/month.

Related Errors & Resources