failover.io
  1. Home
  2. Cloudflare errors
  3. Error 522

Cloudflare error 522: the connection to your server timed out

HTTP 522 from Cloudflare. Connection to the origin timed out: what it means, whose fault it is and how to fix it.

Updated 19 November 20265 min read

Cloudflare returns a 522 when it couldn't open a connection to your origin server in time. It sends the first TCP packet and waits; if no answer comes within 19 seconds, or the server accepts the connection but doesn't acknowledge the request within 90 seconds, Cloudflare gives up and shows 522.

Quick answer. Your origin is overloaded or offline, a firewall is dropping Cloudflare's packets or the DNS record points to the wrong IP. Check that the server is up and not out of CPU or memory, that the A record matches your server and that every Cloudflare IP range from cloudflare.com/ips is allowed on ports 80 and 443, for all TCP traffic and not only new connections.

Is error 522 my fault?

Where the problem isHow often
Your originAlmost always
CloudflareRarely
The visitorNo

A 522 is an origin-side failure nearly every time. Your server can even look fine to you while it fails Cloudflare's connections, because your own requests don't come from Cloudflare's addresses.

A timeout is not a refusal

A 521 means the server actively refused. A 522 means silence: Cloudflare sent the opening SYN packet and never got the SYN+ACK that completes the handshake. Cloudflare retries the SYN several times within those 19 seconds, then stops.

Silence usually has one of two causes: the server is too busy to answer, or a firewall drops packets instead of rejecting them. A drop gives you a 522 and a reject gives you a 521, which is why the fixes differ.

Common causes, most likely first

  1. A firewall drops Cloudflare's packets. Cloudflare names this the most common cause: iptables, UFW, CSF, a hosting panel's security layer or a rate limit that throttles Cloudflare's IP ranges. Allow all current ranges from cloudflare.com/ips on 80 and 443, for all TCP traffic. A rule that lets the first packet through and drops what follows produces exactly this error.
  2. The origin is overloaded, with CPU at 100%, memory full or no free worker to take a new connection. The server is up but can't answer. Run top or htop when the errors happen.
  3. The DNS record in Cloudflare points to an old or wrong IP, often after a server move. Make sure the A or AAAA record matches the address your host gave you.
  4. Keep-alive is turned off on the origin. Cloudflare reuses connections, and a server that closes each one forces a new handshake every time, which makes timeouts more likely under load. In nginx that's keepalive_timeout 75;, in Apache KeepAlive On.
  5. Packets get lost between Cloudflare and your host. This is rarer and outside your control, but an MTR from the origin to a Cloudflare IP from your access logs shows it.

How to fix error 522

  1. Check cloudflarestatus.com to rule out a Cloudflare incident.
  2. Test the origin from another machine, bypassing Cloudflare: curl -v --connect-timeout 10 --resolve yourdomain.com:443:ORIGIN_IP https://yourdomain.com/. A hang confirms the timeout; "connection refused" means you have a 521 problem instead.
  3. Log in to the origin and look at CPU and memory with htop.
  4. Go through the firewall rules for Cloudflare's ranges and make sure established and related traffic is allowed, not only new connections.
  5. If the problem stays, run mtr from the origin to a Cloudflare IP from your logs and send the result to your host or Cloudflare support.

Is error 522 permanent?

No. A 522 lasts as long as its cause: it clears when the server recovers from the load spike, when the firewall stops dropping Cloudflare or when the DNS record is fixed. Visitors don't need to do anything, and refreshing only helps once the origin answers again.

Get alerted when it happens

Overload-driven 522s come and go, so they're easy to miss. An HTTP monitor fails when Cloudflare returns 522 and starts your alert chain; failover.io confirms the failure from a second location before alerting, so one bad network path doesn't page you. More in why uptime checks need a second location.

All six codes side by side: Cloudflare 5xx errors explained.

Frequently asked questions

What does Cloudflare error 522 mean?

Cloudflare couldn't open a connection to your origin in time: no answer to its first packet within 19 seconds, or no acknowledgment of the request within 90 seconds after connecting.

How do I fix Cloudflare error 522?

Make sure the origin is up and not out of CPU or memory, that the DNS record in Cloudflare has the right IP, that every Cloudflare IP range is allowed for all TCP traffic on ports 80 and 443 and that keep-alive is on.

Is error 522 my fault?

Nearly always it's the origin: a firewall dropping Cloudflare's packets, an overloaded server or a wrong DNS record. Cloudflare itself rarely causes it, and the visitor never does.

Why do I get a 522 when my server looks online?

Your own requests don't come from Cloudflare's addresses, so they can work while a firewall drops Cloudflare's packets or the server is too busy to take Cloudflare's connections.