Error 521 Web Server Is Down — Fix Guide

Last tested: November 11, 2026 · By Alex

Error 521 Web Server Is Down is the Cloudflare page you see when Cloudflare tried to open a connection to your origin server and the origin said no. Not “later”, not “something broke halfway” – a flat refusal. In network terms, the origin answered Cloudflare’s connection attempt with a TCP reset, so no HTTP request was ever sent.

That refusal has only a handful of sources: the web server process is stopped, nothing listens on the port Cloudflare uses, or a firewall actively rejects Cloudflare’s IP addresses. If you searched for “Cloudflare origin server refused connection”, this is the same problem. The good news: a refusal is fast and easy to reproduce, so a 521 is usually one of the quickest Cloudflare errors to pin down.

Quick Fix

  • Check that Nginx, Apache or LiteSpeed is running: sudo systemctl status nginx (or apache2, httpd, lsws).
  • Check that it listens on a public address on port 80 and 443: sudo ss -tlnp.
  • Match the port to your Cloudflare SSL/TLS mode: Flexible uses port 80, Full and Full (strict) use port 443.
  • Allow all Cloudflare IP ranges in UFW, iptables, CSF, Fail2ban and any hosting-level firewall.
  • Confirm the A (and AAAA) record in Cloudflare DNS points to the current production server.
  • Still refused? Send your host the Ray ID, the time and the result of a direct curl test.

Visitors cannot fix a 521. If you only run into it on someone else’s site, wait a few minutes and try again; the owner has to bring the origin back.

What Error 521 Means

Diagram of where Error 521 comes from: visitor, CDN edge sending a SYN, origin port 80 or 443 answering with a reset, and the edge showing Error 521

Before Cloudflare can forward a request, it has to open a TCP connection from its edge to your origin IP. Three things can happen to that first SYN packet:

  • The origin answers with SYN+ACK. The connection opens and the request goes through (or fails later with a different code).
  • The origin answers with a reset (RST). The port is closed or a firewall rejects the packet. Cloudflare shows 521.
  • Nothing comes back. The packet is dropped or lost. Cloudflare keeps retrying and then shows Error 522.

So the title “Web server is down” is only half right. The machine is usually up and reachable – a refusal proves something answered. What is missing is a web server that accepts Cloudflare on the right port. Cloudflare itself lists two main causes: an offline web server application and blocked Cloudflare requests.

521 vs 520, 522 and 523

CodeWhat Cloudflare sawFirst thing to check
521Connection refused immediately (RST)Web server status, listening ports, firewall REJECT rules
522No answer to the connection attempt, or no ACK for the requestOverload, DROP rules, wrong IP
520Connected, but the reply was empty or invalidCrashes, resets, header size
523No route to the origin address at allDNS record, routing
1033Cloudflare Tunnel has no healthy connectorcloudflared service

The browser-side twin of 521 is ERR_CONNECTION_REFUSED: same refusal, but seen directly by the visitor without Cloudflare in between.

Common Causes of Error 521

1. The Web Server Service Is Stopped or Crashing

Start with the obvious. Servers crash. A config change with a syntax error stops Nginx from restarting, an Apache reload fails after a module update, LiteSpeed stops after a license or update problem, or the kernel kills the web server when RAM runs out. As soon as no process owns port 80/443, the kernel itself answers every connection with a reset – that is a textbook 521.

On shared hosting the same thing happens when an account is suspended or hits its process limit. On VPS and cloud servers, a reboot after updates can leave the web server disabled at boot.

2. A Firewall Rejects Cloudflare IP Addresses

This is the cause Cloudflare mentions most often. All your visitors now arrive from a relatively small set of Cloudflare addresses, so tools that count connections per IP – CSF/LFD, Fail2ban, iptables connlimit rules, Imunify360, hosting DDoS filters – can decide a Cloudflare IP is attacking you and block it. If the rule uses REJECT, Cloudflare gets a refusal and shows 521. If it uses DROP, the same block shows as 522 instead.

A typical pattern is a 521 that affects only some visitors or some countries, because only a few Cloudflare data centers got banned. WordPress plugins such as Wordfence cannot cause a 521 by themselves – they run after the connection is open – but their server-level firewall modes and host integrations can.

3. Nothing Listens on the Port Your SSL Mode Needs

Cloudflare picks the origin port from your SSL/TLS encryption mode. With Flexible it connects to port 80. With Full or Full (strict) it connects to port 443. A server with no HTTPS virtual host refuses Cloudflare the moment someone switches the mode from Flexible to Full. The reverse also happens: a hardened server that closed port 80 starts returning 521 when the mode is set back to Flexible.

Cloudflare’s documentation is explicit here: in Full or Full (strict) your origin must support HTTPS, with a Cloudflare Origin Certificate or another valid certificate. If 443 accepts the connection but the TLS handshake fails, you get Error 525 instead; if the certificate is rejected in strict mode, Error 526.

4. The Server Listens on the Wrong Address

The service runs, the port is right, and Cloudflare is still refused. Look at the address part of the listen directive. listen 127.0.0.1:80; in Nginx, an app server bound to localhost only, or a Docker container whose port was never published to the host all accept local tests and refuse everything coming from outside.

IPv6 belongs here too. If your zone has an AAAA record, Cloudflare may connect to the origin over IPv6. A server that listens only on IPv4, or an IPv6 address that now belongs to another machine, refuses those connections, and the 521 looks random.

5. DNS Points to an Old or Wrong Server

After a migration, the proxied A record often still points to the old server, a staging box or a load balancer that no longer serves the site. That machine is alive, so it refuses rather than times out. Compare the origin IP in the Cloudflare DNS tab with the IP your host shows for the account. Changes made to DNS recently are covered in Website Not Working After DNS Change.

6. A Port Override or Upstream Proxy Refuses

Origin Rules can change the destination port. If a rule sends traffic to port 8080 or 8443 and nothing listens there, the result is 521 for exactly the paths that rule matches. Similar refusals come from a load balancer or front proxy with no healthy backend that answers with a reset instead of a 502 Bad Gateway.

Check That the Web Server Is Running and Listening

Terminal showing ss -tlnp with nginx listening only on 127.0.0.1:80, no socket on port 443, and curl --resolve failing with Connection refused

Work from the origin outward. These commands run on the server; replace example.com and 203.0.113.10 with your domain and the real origin IP.

Service status and logs

sudo systemctl status nginx        # or: apache2, httpd, lsws
sudo journalctl -u nginx --since "1 hour ago" --no-pager | tail -n 30
sudo nginx -t                      # Apache: sudo apachectl configtest
sudo systemctl enable --now nginx  # start now and at boot

If the config test fails, the service will not start: fix the reported line first. If the journal shows the process being killed, check memory with sudo dmesg -T | grep -i "killed process" and the memory exhaustion guide.

Listening sockets

sudo ss -tlnp | grep -E ':(80|443)\b'
# older systems
sudo netstat -tlnp | grep -E ':(80|443) '

# good:  LISTEN 0 511 0.0.0.0:443  users:(("nginx",...))
# good:  LISTEN 0 511    [::]:443  users:(("nginx",...))
# bad:   LISTEN 0 511 127.0.0.1:80 (local only)
# bad:   no line for :443 while SSL mode is Full

Read the result against your SSL/TLS mode. An empty result for 443 under Full is the whole story. A line for 0.0.0.0 but none for [::] matters only if you have an AAAA record.

Reproduce the refusal from outside

Run this from your own computer, not from the server, so the test crosses the same firewall Cloudflare does:

# HTTPS straight to the origin, skipping Cloudflare
curl -svo /dev/null https://example.com/ --resolve example.com:443:203.0.113.10

# Plain HTTP (Flexible mode)
curl -svo /dev/null http://example.com/ --resolve example.com:80:203.0.113.10

# Port check only
nc -vz -w 5 203.0.113.10 443
ResultMeaningNext step
Failed to connect ... Connection refusedOrigin or a REJECT rule refuses everyoneService, listen address, firewall
Page loads normallyOrigin is fine for your IPFirewall rules that target Cloudflare ranges
Hangs, then timed outPackets are dropped, not refusedRead the Error 522 guide
TLS or certificate errorPort open, HTTPS brokenError 525 / 526

The second row is the classic firewall case: the site works when you test it, yet Cloudflare is refused, because only Cloudflare addresses are blocked. If you see the third row, the cause is not a refusal at all; the 521 you saw earlier may have been a short outage, so check uptime monitoring and logs for the exact time.

Step-by-Step Fix for Error 521

Five-step Error 521 fix path: start the web server, listen on public ports 80 and 443, allow edge IP ranges, match the port to the SSL mode, verify the origin IP in DNS

Step 1: Bring the Web Server Back

Fix the config error, start the service and make sure it is enabled at boot. If it stops again within minutes, the real problem is underneath: memory kills, a crashing module or a full disk (df -h). Restarting PHP-FPM alone does not help a 521; it is the front web server that must accept the connection.

Step 2: Allow Every Cloudflare Range

Take the current list from cloudflare.com/ips (IPv4 and IPv6) and allow it on ports 80 and 443. Then look for rules that still reject those addresses:

# UFW
for ip in $(curl -s https://www.cloudflare.com/ips-v4) $(curl -s https://www.cloudflare.com/ips-v6); do
  sudo ufw allow proto tcp from "$ip" to any port 80,443 comment 'Cloudflare'
done
sudo ufw reload

# iptables: find REJECT rules and the reject-with type
sudo iptables -L INPUT -n -v --line-numbers | grep -E 'REJECT|DROP'
sudo ip6tables -L INPUT -n -v --line-numbers | grep -E 'REJECT|DROP'

# CSF: allow and ignore each range, then reload
sudo csf -g 173.245.48.1        # is this Cloudflare IP blocked?
sudo csf -r

# Fail2ban: unban a Cloudflare address
sudo fail2ban-client set <jail> unbanip <cloudflare-ip>

Ask your host about network-level firewalls you cannot see, and add the same ranges to a cloud security group (AWS, Google Cloud, Oracle and others block everything not explicitly allowed). Finally, restore the real visitor IP in the web server (Nginx real_ip_header CF-Connecting-IP, Apache mod_remoteip) so that ban tools punish attackers instead of Cloudflare. If you need to block countries or bots, do it in Cloudflare with WAF rules – see Cloudflare Error 1020 for how those blocks look to visitors.

Step 3: Match the Port to the SSL/TLS Mode

Open SSL/TLS in the Cloudflare dashboard and note the mode. For Full or Full (strict), the origin needs an HTTPS server block on 443 with a certificate: a free Cloudflare Origin Certificate is enough for both modes. Check what the server actually serves:

sudo nginx -T 2>/dev/null | grep -E 'listen .*443|ssl_certificate '
sudo apachectl -S 2>/dev/null | grep -E ':443|port 443'
sudo ufw status | grep -E '80|443'

Avoid fixing a 521 by dropping to Flexible as a permanent solution. It hides the problem and invites redirect loops when WordPress also forces HTTPS.

Step 4: Fix the Listen Address and IPv6

Change listen 127.0.0.1:80 to listen 80 (and add listen [::]:80 and listen [::]:443 ssl if you publish an AAAA record). For containers, publish the port to the host (-p 80:80) or put a reverse proxy in front. If you do not run IPv6 on the origin, remove the AAAA record rather than leave Cloudflare a dead address.

Step 5: Verify DNS and Port Overrides

Compare every proxied A and AAAA record with the server’s real address (curl -4 ifconfig.me on the server). Check Rules > Origin Rules for destination port changes, and Load Balancing pools for unhealthy origins. If a record points to a Cloudflare IP address instead of your server, you get Error 1000 rather than 521.

Step 6: Retest Through Cloudflare

Reload the site through Cloudflare from two networks (Wi-Fi and mobile data) to hit different Cloudflare data centers. A 521 page is generated live, so there is nothing to purge. If the error disappears for you but monitoring still reports it from some regions, a firewall is still banning part of the Cloudflare ranges.

Why Error 521 Comes and Goes

An intermittent 521 is usually not the web server. It is a ban tool that blocks a Cloudflare IP for ten minutes, unblocks it and bans it again; a hosting DDoS filter that kicks in during traffic peaks; or a server that reaches its process limit and refuses new connections until load drops. Match the times in your uptime monitor with the firewall log (/var/log/lfd.log, /var/log/fail2ban.log) and the web server journal. If the times line up with peaks, plan capacity; if they line up with bans, fix the allowlist. If the site fails for you while a friend loads it fine, read this guide to location-specific outages.

When to Contact Your Host

Contact support if the server is refused even from your own IP and you have no shell access, or if the server runs and listens but Cloudflare is still refused (a network firewall upstream of your server). Give them: the Ray ID and UTC time from the 521 page, your origin IP, the SSL/TLS mode, and the output of the curl --resolve test. Ask one direct question: “Are any Cloudflare IP ranges blocked or rate limited on ports 80 or 443?”

Frequently Asked Questions

What does Error 521 Web Server Is Down mean?

Your origin server rejected the connection that Cloudflare opened toward it. No request reached your site, usually because the web server is stopped, the port is closed or a firewall rejects Cloudflare.

Is Cloudflare origin server refused connection the same as Error 521?

Yes. That phrase describes Error 521 exactly: the origin answered the connection attempt from Cloudflare with a refusal instead of accepting it.

Can my server be online and still show Error 521?

Yes. A running server still causes 521 if nothing listens on port 80 or 443, if the web server listens only on localhost or IPv4, or if a firewall rejects Cloudflare IP ranges.

Which port does Cloudflare use to reach my origin?

Port 80 when the SSL/TLS mode is Flexible and port 443 when it is Full or Full (strict), unless an Origin Rule overrides the destination port.

What is the difference between Error 521 and Error 522?

A 521 is an immediate refusal from the origin. A 522 means Cloudflare got no answer in time, which usually points to dropped packets, an overloaded server or a wrong IP address.

Can a WordPress plugin cause Error 521?

Not directly, because plugins run after the connection is accepted. Server-level firewalls linked to security plugins or hosting panels can block Cloudflare IPs, and a crashed web server after a plugin change can also lead to 521.

Final Summary

Error 521 means the origin refused Cloudflare at the door. Check that the web server runs, listens on a public address on the port your SSL/TLS mode requires, and that no firewall rejects Cloudflare ranges. Confirm the DNS record points to the current server, retest with curl --resolve, and keep the allowlist current. Our website error troubleshooting hub lists every other code by layer.

Other Errors on the Cloudflare-to-Origin Path

Leave a Comment