Cloudflare 521 / 522 / 523: the web server is down

PlatformAny website Doing it yourself15 to 45 minutes, often with the host Checked

Written and checked by Sajid, Founder & Web Engineer

The short answer

These errors come from Cloudflare, and they all mean the same thing: Cloudflare could not reach your actual server (the origin). 521 is the server refusing the connection, 522 is it timing out, 523 is Cloudflare unable to find it. The visitor sees Cloudflare, but the problem is your server or the connection to it, usually the server being down, overloaded, or blocking Cloudflare. Getting the origin back up, or unblocking Cloudflare, clears it.

Is this your problem?

  • A Cloudflare-branded error: 521 "Web server is down", 522 "Connection timed out", or 523 "Origin is unreachable"
  • It comes and goes, or appears under load
  • The site is unreachable through the domain but the server may respond on its direct IP
  • It started after a host move, an IP change, or a server restart
  • Only pages through Cloudflare fail; the origin itself may be fine

What usually causes it

1
The origin server is down or restarting

How to tell: The web server, or the whole machine, crashed, is restarting, or ran out of resources, so Cloudflare gets nothing back.

2
The server is blocking Cloudflare

How to tell: A firewall on the server is blocking Cloudflare's IP ranges, so the connection is refused (521).

3
The server is too slow to answer

How to tell: Under load the origin takes too long and Cloudflare times out (522).

4
Wrong origin IP in Cloudflare DNS

How to tell: The A record in Cloudflare points at an old or wrong server address (523), so there is nothing there.

5
SSL or port misconfiguration

How to tell: The origin is not listening on the expected port, or its certificate setup is broken for strict SSL mode.

Before you touch anything

  • Note which code it is (521, 522, 523); each points at a slightly different cause.
  • Check your host status page and whether the server responds on its direct IP, to tell "server down" from "Cloudflare cannot reach it".

How to fix it, step by step

  1. 1

    Check the origin server is up

    Ask your host, or load the server by its direct IP or a temporary URL. If the server itself is down or overloaded, that is the fix: restart or scale it.

  2. 2

    Allow Cloudflare through the firewall

    For a 521, the server firewall is likely blocking Cloudflare. Allow-list Cloudflare's published IP ranges so the server accepts its connections.

  3. 3

    Fix a timeout (522)

    A 522 means the origin is too slow or out of resources. Check server load and the PHP or app process; raise capacity, or fix what is making it slow.

  4. 4

    Check the origin IP in Cloudflare DNS

    For a 523, confirm the A record in Cloudflare points at the correct current server IP. A wrong or old IP has nothing to answer.

  5. 5

    Check the port and SSL mode

    Make sure the origin listens on the expected port, and that Cloudflare's SSL mode matches what the origin supports (Full strict needs a valid origin certificate).

  6. 6

    Pause Cloudflare to isolate it

    Temporarily set the record to DNS-only (grey cloud) so traffic skips Cloudflare. If the site then loads, the issue is the Cloudflare-to-origin link; if not, it is the origin.

Stop and get help if

  • The origin server is down or overloaded and only the host can bring it back or scale it.
  • It is a shop or booking site losing sales while it is unreachable.
  • You do not manage the server firewall or the host, and the fix is on their side.
Fix it for me

Stop it happening again

  • Allow Cloudflare's IP ranges on the server firewall so it is never blocked.
  • Size the server for your traffic, including spikes, so it does not time out.
  • Keep the origin IP in Cloudflare correct after any host or server move.
  • Monitor uptime so a flapping 521 or 522 reaches you before customers do.

Questions people ask

Is the error Cloudflare's fault?

Rarely. Cloudflare is reporting that it could not reach your server. The problem is almost always the origin or the connection to it.

What is the difference between 521, 522 and 523?

521 is the server refusing the connection, 522 is it timing out, 523 is Cloudflare unable to find it. All mean Cloudflare could not reach your origin.

My server is up but still 521. Why?

The server firewall is most likely blocking Cloudflare. Allow-list Cloudflare's IP ranges and it clears.

Not sure where your site stands?

Paste the address. Security, speed, SEO and how old the tech is, in about ten seconds.

Still broken? We can fix it.