DEV Community

Cover image for Cloudflare Errors 521, 522, 525 and 526: What Each Means and How to Fix It
epifive
epifive

Posted on Originally published at epifive.com

Cloudflare Errors 521, 522, 525 and 526: What Each Means and How to Fix It

Cloudflare errors 521, 522, 525 and 526 all mean Cloudflare is working but cannot get a good answer from your origin server. A 521 means the origin refused the connection, a 522 means the connection timed out, a 525 means the TLS handshake failed, and a 526 means the origin's certificate could not be validated. Each one has a short list of causes on the origin side, and you can usually find yours in a few minutes.

Who this is for

This guide is for site owners, developers and small-team administrators who run a site or app behind Cloudflare's proxy (the orange cloud) on their own VPS, a shared host or a cloud VM, and now see a Cloudflare-branded error page instead of their site. By the end you will know which error you have, what Cloudflare says causes it, which origin settings to check, and how to set the SSL/TLS mode and certificate so 525 and 526 stay away.

Everything below follows Cloudflare's own documentation, opened on 2026-11-29. Cloudflare Pages and Workers have a few special cases, noted where they apply.

The four errors at a glance

The Cloudflare 5xx index describes them as: 521 "Web server is down", 522 "Connection timed out", 525 "SSL handshake failed" and 526 "Invalid SSL certificate". The same index lists 520 (unknown error from the web server), 523 (origin is unreachable) and 524 (a timeout occurred), which this guide does not cover.

Code Cloudflare's title What it means Where to look first
521 Web server is down The origin refuses connections from Cloudflare Is the web server running? Does the firewall allow Cloudflare IPs?
522 Connection timed out Cloudflare got no answer in time Firewall rate limits, overloaded or offline origin, wrong origin IP in DNS
525 SSL handshake failed TLS handshake with the origin failed (Full or Full (strict) mode) Certificate installed, port 443 open, SNI, ciphers
526 Invalid SSL certificate Origin certificate cannot be validated (Full (strict) mode) Expired, self-signed, wrong name, missing chain

A useful rule: 521 and 522 are about reaching the origin at all, while 525 and 526 are about the encrypted connection after it is reached. If you recently turned on Full or Full (strict) mode and the errors began right after, start with the SSL/TLS section.

Prerequisites

Before you change anything, gather these:

  1. Access to the Cloudflare dashboard for the zone, with permission to edit SSL/TLS settings.
  2. Shell or control-panel access to the origin server, or the hosting provider's support channel.
  3. The origin's real IP address, and the hostname the site uses.
  4. The time (with timezone) and URL of a failing request, which Cloudflare's hosting-provider checklist asks for.

Cloudflare's guidance also says the cause is not always in the origin web server's own error logs, so check logs on any load balancer, cache, proxy or firewall that sits between Cloudflare and the origin.

Step 1: Confirm the origin works without Cloudflare

Test the origin directly, bypassing Cloudflare's proxy. Replace the IP with your origin and the hostname with your site:

curl -sI --resolve www.contoso.com:443:203.0.113.10 https://www.contoso.com/ -k
curl -sI --resolve www.contoso.com:80:203.0.113.10 http://www.contoso.com/
Enter fullscreen mode Exit fullscreen mode

The --resolve option makes curl connect to the IP you give while sending the real hostname. The -k flag skips certificate validation so you can tell "origin down" apart from "certificate problem". Run the commands from a machine that is not blocked by the origin's firewall.

  • If both fail with "connection refused", the web server is not listening: see the 521 section.
  • If they hang, packets are being dropped or the server is overloaded: see the 522 section.
  • If HTTP works but HTTPS fails, the problem is the certificate or port 443: see the 525 and 526 sections.

Fixing error 521: Web server is down

Cloudflare explains that a 521 occurs when the origin web server refuses connections from Cloudflare. Its listed common causes are an offline origin web server application, or Cloudflare requests being blocked by security software at the origin.

Work through Cloudflare's resolution list in order:

  1. Confirm the origin web server is responsive. On Linux, check the service and the listening ports:
sudo systemctl status nginx
sudo ss -tlnp | grep -E ':(80|443)\b'
Enter fullscreen mode Exit fullscreen mode
  1. Check origin error logs for application crashes or outages. Look at the web server's error log and the application's log for the minute the error appeared.
  2. Make sure Cloudflare IP addresses are not blocked or rate limited. Cloudflare says to allow its IP ranges in the origin's firewall or security software. The authoritative lists are at https://www.cloudflare.com/ips-v4 and https://www.cloudflare.com/ips-v6. Fail2ban, CSF, ModSecurity and hosting-provider firewalls are common places for an automatic block, because every visitor appears to come from a small set of Cloudflare addresses.
  3. Match the port to the SSL/TLS mode. Cloudflare's page says the origin application must listen on port 80 for Flexible mode, or port 443 for Full and Full (strict). If you switched modes and the origin only serves one port, you get a 521.
  4. If the mode is Full or Full (strict), confirm the origin supports HTTPS and has a valid certificate, such as a Cloudflare Origin Certificate.

If you are on shared hosting and cannot change the firewall, send your provider the error details listed in Cloudflare's checklist: the code and message, the time with timezone, and the URL.

Allowing Cloudflare IPs on a Linux firewall

If your origin uses ufw, you can allow the published ranges for HTTPS like this. This example uses curl to fetch the current lists, so rerun it whenever Cloudflare updates them:

for ip in $(curl -s https://www.cloudflare.com/ips-v4; echo; curl -s https://www.cloudflare.com/ips-v6); do
  sudo ufw allow from "$ip" to any port 443 proto tcp
done
Enter fullscreen mode Exit fullscreen mode

Review your existing rules first. If you plan to block all other traffic to port 443, make sure you still have another way in (such as SSH from your own address) and that you also allow port 80 if you use Flexible mode or HTTP redirects. Cloudflare's own page for the ranges describes itself as the definitive source, so do not copy ranges from old blog posts.

Fixing error 522: Connection timed out

A 522 means Cloudflare timed out contacting the origin. Cloudflare's page describes two timeouts:

  • Before the TCP connection is established: Cloudflare does not receive a SYN+ACK within 19 seconds of sending a SYN. Its SYN retries back off at 1, 1, 1, 1, 1, 2, 4 and 8 seconds.
  • After the TCP connection is established: Cloudflare receives no data above the TCP layer, for example a Server Hello during TLS negotiation, within 90 seconds.

Cloudflare tells you to contact your hosting provider and check these common issues:

  1. Cloudflare IP addresses rate limited or blocked in .htaccess, iptables or firewalls. Cloudflare calls this the most common cause and says to confirm all Cloudflare IP ranges are allowed.
  2. The origin server is overloaded or offline and drops requests.
  3. TCP keepalives are disabled at the origin.
  4. The origin IP in the Cloudflare DNS app does not match the server's current IP. After a server move or an IP change, this is the first thing to check.
  5. Packets are dropped at the origin.

To find out whether the problem affects the whole site or specific paths, Cloudflare suggests Origin Analytics. A high failure rate on particular paths in the Top endpoints table points to a path-specific problem, not a general outage.

522 on Cloudflare Pages, Workers and Origin Rules

Cloudflare lists three platform-specific causes:

  • Cloudflare Pages: confirm a custom domain is set up and the CNAME points to your custom Pages domain.
  • Workers with a Custom Domain: a fetch to the Worker's own hostname causes a 522. Use a Route targeting another hostname, or enable the global_fetch_strictly_public compatibility flag.
  • Origin Rules: make sure the resulting hostname resolves. An A record pointing to a reserved address such as 100:: or 192.0.2.0 returns a 522.

If none of this helps, Cloudflare says to gather a traceroute or MTR from the origin to a Cloudflare IP that recently connected, plus the host's logs and investigation notes, before contacting Cloudflare support.

Choosing the right SSL/TLS mode

Errors 525 and 526 depend on the mode, so settle this before debugging certificates. Cloudflare's SSL/TLS modes page describes five modes:

Mode Connection from Cloudflare to origin Origin certificate checked?
Off No encryption, plain HTTP Not applicable
Flexible Unencrypted HTTP (visitor to Cloudflare can use HTTPS) Not applicable
Full Matches the visitor's protocol (HTTP or HTTPS) No, self-signed or invalid certificates are accepted
Full (strict) Same as Full, HTTPS when the visitor uses HTTPS Yes, from a public CA such as Let's Encrypt or Cloudflare Origin CA
Strict (SSL-Only Origin Pull) Always HTTPS Yes, same issuer options as Full (strict)

To change it, go to the SSL/TLS Overview page in the Cloudflare dashboard and choose an encryption mode. To set a mode manually, select the Custom SSL/TLS option. Automatic SSL/TLS is the default on zones that have been migrated, and a configuration rule can apply a different mode to specific hostnames.

For a production site, Full (strict) with a valid certificate on the origin is the setup that protects traffic end to end. Flexible leaves the Cloudflare-to-origin leg unencrypted, so use it only when the origin truly cannot serve TLS.

Fixing error 525: SSL handshake failed

Cloudflare says a 525 occurs when both of these are true: the TLS handshake between Cloudflare and the origin fails, and your zone uses Full or Full (strict) mode.

Ask your hosting provider, or check yourself, for these origin-side causes from Cloudflare's page:

  • No valid SSL certificate is installed.
  • Port 443 (or another custom secure port) is closed.
  • SNI is not supported.
  • Cipher suites do not match those Cloudflare uses.
  • A key exchange compliance requirement is enabled but the destination server does not support the required algorithm.

Test the handshake with SNI from any machine that can reach the origin:

openssl s_client -connect 203.0.113.10:443 -servername www.contoso.com </dev/null
Enter fullscreen mode Exit fullscreen mode

Look for a certificate chain in the output and a line starting with Verify return code. A handshake that ends immediately with an alert or no certificate points at SNI, ciphers or a closed port. On Apache, mod_ssl errors in the error log can show the cause, and on nginx the error log does the same. Cloudflare's page recommends these checks for intermittent 525s: verify a certificate is installed, review the server's cipher suites for compatibility, and check logs from the times the errors occurred for connection resets during the handshake.

The key exchange compliance trap

Cloudflare documents a cause that is easy to miss. If a compliance requirement is set under SSL/TLS > Overview > Origin connection & post-quantum encryption, Cloudflare limits outbound TLS 1.3 to the key agreements that requirement permits. Servers that do not support them fail with a 525:

  • With the post-quantum hybrid option, only X25519MLKEM768 is advertised.
  • With the FIPS option, only FIPS-approved curves are advertised, so servers supporting only X25519 fail.

This also affects outbound fetch() calls from Workers in that zone, including calls to third-party APIs. To fix it, remove the compliance requirement. Cloudflare says Automatic key exchange, the default, negotiates a mutually supported algorithm and works with more servers, and it does not recommend a specific compliance setting because that depends on your organization's obligations.

Using Origin Analytics for 525

In Origin Analytics, the Origin status codes chart shows whether specific endpoints are affected. Cloudflare says a status of 0 means Cloudflare received no HTTP response from the origin, which can indicate a TLS negotiation failure; compare those timestamps with your origin's SSL logs.

Fixing error 526: Invalid SSL certificate

A 526 means Cloudflare cannot verify the certificate on your origin. Cloudflare says both conditions must be true: it cannot validate the origin's certificate, and the SSL/TLS Overview tab is set to Full (strict).

Cloudflare's resolutions:

  1. Quick fix: change the SSL mode from Full (strict) to Full. This stops Cloudflare checking the certificate, so treat it as temporary.
  2. Self-signed certificate: add it to the Custom Origin Trust Store.
  3. Origin CA: install a Cloudflare Origin CA certificate at the origin.
  4. Server checks: ask your administrator or host to confirm that the certificate is not expired or revoked, is signed by a certificate authority and not self-signed, covers your domain in the Common Name or Subject Alternative Name, comes with a complete chain of intermediate certificates, and is served on port 443.
  5. Verification: pause Cloudflare and test the hostname with an SSL checker.

You can check expiry and names from a shell:

openssl s_client -connect 203.0.113.10:443 -servername www.contoso.com </dev/null 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates -ext subjectAltName
Enter fullscreen mode Exit fullscreen mode

The output shows the subject, issuer, notBefore and notAfter dates and the names the certificate covers. If www.contoso.com is not in the Subject Alternative Name list, or notAfter is in the past, you have found the 526.

For Cloudflare Zero Trust (Gateway), Cloudflare adds that a 526 can come from an untrusted issuer, a revoked or expired certificate in the chain, a Common Name that does not match the URL, or invalid characters such as underscores. It can also come from weak ciphers (RC4, 3DES), missing FIPS-compliant ciphers when FIPS mode is on, or an HTTPS-to-HTTP redirect. Worker subrequests to external hostnames outside your zone that are not proxied by Cloudflare always use Full (strict), so the external certificate must be valid, or you add a self-signed certificate to the Custom Origin Trust Store and enable the cots_on_external_fetch compatibility flag.

Installing a Cloudflare Origin CA certificate

An Origin CA certificate encrypts traffic between Cloudflare and your origin and works with Full (strict). Cloudflare's page describes how it is created and installed:

  1. In the dashboard, go to SSL/TLS > Origin Server, open the Origin Certificates tab and select Create Certificate. You need API access on your account to create or revoke them.
  2. Choose whether Cloudflare generates the private key and CSR (RSA or ECC) or you upload your own CSR, and choose the certificate validity.
  3. Copy the certificate and the private key into separate files. You cannot view the private key again after leaving the creation screen.
  4. Upload both to the origin and update the web server configuration, enable SSL on port 443, and add the Cloudflare Origin CA root certificate if your server requires it.
  5. Set the mode to Full (strict), globally or per hostname.

An nginx server block, with example paths, looks like this:

server {
    listen 443 ssl;
    server_name www.contoso.com;
    ssl_certificate     /etc/ssl/cloudflare/contoso.com.pem;
    ssl_certificate_key /etc/ssl/cloudflare/contoso.com.key;
}
Enter fullscreen mode Exit fullscreen mode

Test with sudo nginx -t and reload with sudo systemctl reload nginx.

Limits from the same page: Cloudflare does not send expiration notifications, so track the expiry date yourself. A certificate can include up to 200 Subject Alternative Names, IP addresses cannot be used as SANs, wildcards cover only one hostname level, and revoking a certificate is irreversible. The certificate only encrypts the leg between Cloudflare and your origin, so visitors may see untrusted certificate errors if you pause Cloudflare or turn off proxying on a hostname that uses it.

If your site is a public Let's Encrypt or commercial certificate already, you do not need Origin CA; just make sure the chain is complete and renewals are working. For help with DNS records in general, see DNS records explained: A, CNAME, MX and TXT, and for what the free Cloudflare plan includes see what you get on the Cloudflare free plan.

Troubleshooting checklist

Use this order when you are not sure which error you have, or after a fix does not stick:

  1. Note the code, the time with timezone and the URL.
  2. Test the origin directly with curl --resolve and openssl s_client.
  3. Confirm the web server is running and listening on 80 and 443.
  4. Confirm Cloudflare IP ranges are allowed and not rate limited in every firewall layer.
  5. Confirm the origin IP in Cloudflare DNS is the server's current IP.
  6. Match the SSL/TLS mode to what the origin serves: Flexible needs port 80, Full and Full (strict) need port 443.
  7. For 525, review cipher suites, SNI and any key exchange compliance requirement.
  8. For 526, check certificate expiry, names, issuer and chain, then move back to Full (strict) if you used Full as a stopgap.
  9. If you still cannot find it, send your host the details Cloudflare asks for.

What we checked

  • Opened Cloudflare's error 521 page on 2026-11-29 (last modified 2026-04-23): causes, the port 80 versus 443 rule for Flexible and Full modes, and the advice to allow Cloudflare IP ranges.
  • Opened Cloudflare's error 522 page on 2026-11-29 and copied the timeouts exactly: 19 seconds for SYN+ACK with retries at 1, 1, 1, 1, 1, 2, 4 and 8 seconds, and 90 seconds for data after the TCP connection is established.
  • Opened the 525 and 526 pages on 2026-11-29 and cross-checked them against the SSL/TLS modes page: 525 and 526 both require Full or Full (strict), and Full does not validate certificates while Full (strict) does.
  • Opened the Origin CA page on 2026-11-29 for the dashboard path (SSL/TLS > Origin Server > Origin Certificates > Create Certificate), the 200-SAN limit and the no-expiry-notification note.
  • Opened the Cloudflare 5xx index (last modified 2026-10-15) to confirm the official titles for 520 through 526, and the three details to send a hosting provider.
  • Opened cloudflare.com/ips, which links the plain-text IPv4 and IPv6 lists used in the firewall example.
  • Not tested hands-on: no Cloudflare account, origin server or firewall was used, and the shell commands were not run here. They are standard curl, openssl and nginx usage, adapted to Cloudflare's documented behavior as of 2026-11-29.

Last tested: 2026-11-29

References


This guide was researched and drafted with AI assistance and checked against the vendor documentation listed in its References. Read the maintained version and related guides on EpiFive.

Top comments (0)