Skip to content
RU

Cloudflare Error 521: Web Server Is Down. Why the Origin Refuses Cloudflare

What it means: Cloudflare reached your origin's IP, but the server refused the connection.

  1. Check the web server process is running
  2. Allow Cloudflare IP ranges in the firewall
  3. Listen on 443 for Full, 80 for Flexible
  4. Verify the origin IP in Cloudflare DNS

Test your URL now

Requests the address and shows the status code and what the server sends back.

What error 521 means

Cloudflare's documentation defines it plainly: "Error 521 occurs when the origin web server refuses connections from Cloudflare" (Cloudflare: Error 521). The visitor sees Cloudflare's "Web server is down" page with a Ray ID, and the HTTP status is 521. Cloudflare itself works; the hop from Cloudflare to your server does not.

"Refuses" is precise: the origin host is reachable on the network and answers the TCP connection attempt with a rejection (a TCP RST, usually because nothing listens on the port, or a firewall rule rejects it). Compare the neighbours:

Common causes

CauseHow to recognise itFix
Web server stopped or crashedsystemctl status nginx (or apache2, caddy) not active; nothing in ss -ltn on 80/443Start it, then find why it stopped in its error log
Firewall or security tool blocks CloudflareThe site loads when you connect to the origin from your own IP, but Cloudflare gets 521; fail2ban or a host firewall lists Cloudflare addressesAllow every range from cloudflare.com/ips
SSL/TLS mode and port disagreeFull or Full (strict) set, but the server has no HTTPS listener; or Flexible set and port 80 closedPort 443 for Full and Full (strict), port 80 for Flexible, as Cloudflare's docs require
Wrong origin address in DNSThe proxied A or AAAA record points to an old or different serverCorrect the record in the Cloudflare DNS tab
AAAA record without an IPv6 listenerThe server listens on IPv4 only, but the zone has an AAAA record for the originListen on IPv6 (listen [::]:443) or remove the AAAA record

The firewall case has a classic trigger. All proxied traffic arrives from Cloudflare addresses, so a brute-force detector that reads raw connection IPs sees one "client" making thousands of requests and bans it. Configure the web server to log the visitor IP from the CF-Connecting-IP header (nginx: set_real_ip_from for each Cloudflare range plus real_ip_header CF-Connecting-IP;) so bans hit attackers, not Cloudflare.

How to fix it

  1. Reproduce while bypassing Cloudflare. Connect to the origin IP directly with the right host name:
    curl -sv --resolve example.com:443:203.0.113.10 https://example.com/ -o /dev/null
    # * connect to 203.0.113.10 port 443 failed: Connection refused
    "Connection refused" reproduces 521. Repeat on port 80 with http:// if you use Flexible.
  2. Check the listener on the origin.
    ss -ltnp | grep -E ':(80|443) '
    systemctl status nginx --no-pager
  3. Check firewall rules for drops or rejects that cover Cloudflare:
    iptables -S | grep -E 'DROP|REJECT'
    nft list ruleset | grep -iE 'drop|reject'
    fail2ban-client status
    Compare banned addresses with curl -s https://www.cloudflare.com/ips-v4 and curl -s https://www.cloudflare.com/ips-v6.
  4. Match the SSL/TLS mode under SSL/TLS, Overview in the dashboard with what the server offers.
  5. Ask the host. Cloudflare recommends sharing the error code, the time with time zone and the failing URL with your hosting provider; managed hosting often has its own firewall in front of your server.

If you are a visitor

A 521 page is about the website's own server, so nothing on your device causes it or fixes it: clearing the cache, changing DNS or switching browsers will not help. The page tells you which part failed. The browser-to-Cloudflare leg is marked as working, the "Host" box shows the error, and the Ray ID at the bottom identifies your request in Cloudflare's logs. If you can reach the site owner, send them that Ray ID and the time you saw the error. Then wait and retry: a 521 caused by a restart or a deploy often clears within minutes, while one caused by a firewall rule lasts until the owner changes it.

How to confirm the fix

curl -s -o /dev/null -w '%{http_code}\n' --resolve example.com:443:203.0.113.10 https://example.com/
# 200
curl -sI https://example.com/ | grep -iE '^(HTTP|server|cf-ray)'
# HTTP/2 200
# server: cloudflare

The first command proves the origin accepts connections; the second, that the proxied site works end to end. Error Analytics in the dashboard (filter by edge status code 521) should drop to zero. The HTTP status checker shows the status your public URL returns from outside your network.

Related errors

60+ Status CodesComplete HTTP status code reference
Search by CodeQuick search for 200, 301, 404, 500
Categories 1xx–5xxInformational, success, redirects, errors
Examples & CausesWhen it occurs and how to fix it

Why teams trust us

60+
status codes
1xx-5xx
all categories
SEO
ranking impact
Free
online reference

How to use the reference

1

Enter code or keyword

2

Find description and causes

3

Apply recommendations

HTTP Status Codes Reference

HTTP status codes are three-digit numbers that the server returns for every request. They tell the browser and search crawlers what happened: success, redirect, or error.

Quick Search

Enter a code or keyword — instant result with description.

All Categories

1xx Informational, 2xx Success, 3xx Redirect, 4xx Client Error, 5xx Server Error.

Causes & Fixes

For each code: typical causes and concrete steps to resolve.

SEO Impact

How each code affects indexing and link juice transfer in Google.

Who uses this

Developers

choosing correct status

SEO

redirect optimization

DevOps

5xx error diagnostics

Marketers

landing page check

Common Mistakes

Confusing 301 and 302301 is permanent (passes SEO equity), 302 is temporary (does not).
Returning 200 on error"Soft 404s" — a 404 page with status 200 — confuse search engines and stay indexed.
Ignoring 5xx errors500, 503 are server failures. Prolonged episodes remove pages from the index.
Redirect chainsA→B→C instead of A→C slows loading and dilutes SEO equity. Simplify chains.

Best Practices

Use 301 for permanent redirectsThis passes 90–99% of link equity to the new URL.
Return 404 for missing pagesDon't mask 404 as 200 — it hurts SEO and UX.
Monitor 5xx in real timeSet up an HTTP monitor that alerts on 5xx.
Use 410 instead of 404410 Gone means "page permanently removed" — Google de-indexes faster.

Monitor HTTP statuses automatically

HTTP monitor alerts when response code changes or 5xx appears.

Sign up free

Learn more

Sources

Frequently Asked Questions

Is Cloudflare down when I see error 521?

No. Cloudflare reached your server and the server refused the connection, so the fault is at the origin: a stopped web server, a firewall or a wrong port.

Why does my site work on its IP but show 521 through Cloudflare?

Your own IP is allowed and Cloudflare's are not, or Cloudflare connects on a different port than you test. Allow all Cloudflare IP ranges and check the SSL/TLS mode port.

Which port does Cloudflare use to connect to my server?

Port 80 in Flexible mode and port 443 in Full and Full (strict), according to Cloudflare's 521 documentation. The origin must listen on the port your mode uses.

What is the difference between 521 and 522?

521 means the origin actively refused the connection. 522 means the origin did not answer the connection attempt at all before Cloudflare timed out.

Can fail2ban cause error 521?

Yes. If it sees Cloudflare addresses instead of visitor IPs, it can ban them. Restore real visitor IPs from the CF-Connecting-IP header and whitelist Cloudflare ranges.

Try the live tool that powered this guide

Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.