Common Cloudflare errors (520 to 526)
Server connection errors
-
Error 520
Unexpected response from the server- Meaning
- The server returned an empty, unknown, or unexpected response to Cloudflare
- Common cause
- A crashed process on the site, blocked Cloudflare addresses, or headers larger than 128 KB
- First check
- The web server and site error logs at the time of the error
Cloudflare connected to the server but didn't get a response it could pass on to the visitor, for example an empty response or one without an HTTP status code. Check the error logs for a process that crashed at the time of the error, make sure the firewall and security plugins aren't blocking Cloudflare's addresses, and reduce large headers, which usually come from many cookies. When the server advertises HTTP/2 but doesn't handle it properly, turn off HTTP/2 to Origin in Cloudflare as a test. Authenticated Origin Pulls enabled in Cloudflare without a matching server setup also causes it.
-
Error 521
The server refused the connection- Meaning
- The web server refused the connection from Cloudflare
- Common cause
- The web server isn't running, or a firewall is blocking Cloudflare addresses
- First check
- Whether the web server listens on ports 80 and 443: sudo ss -tlnp
This error appears when the web service on the server is down, or when a firewall or security software blocks some of Cloudflare's IP addresses. Make sure the web server is running, check the error logs for a crash, allow all of Cloudflare's IP ranges in the firewall, and check that fail2ban or CSF hasn't blocked them. In Full and Full (strict) modes, the server must accept HTTPS connections on port 443, and in Flexible mode, HTTP connections on port 80.
-
Error 522
Connection timed out- Meaning
- Cloudflare couldn't complete the connection to the server in time
- Timeouts
- 19 seconds to establish the TCP connection, and 90 seconds for data once it's established
- Common cause
- Cloudflare addresses blocked or rate limited in the firewall
According to Cloudflare, the most common cause is blocking or rate limiting Cloudflare addresses in .htaccess, iptables, or the firewall. Other causes are an overloaded or offline server, Keepalive turned off on the web server, an IP address in the Cloudflare DNS record that isn't the server's current address, and packet loss on the network. Allow all of Cloudflare's ranges, compare the A record with the server's address, and check the load. If the problem persists, run MTR or traceroute from the server to the Cloudflare address shown in the access logs.
-
Error 523
The server is unreachable- Meaning
- Cloudflare can't reach the server over the network
- Common cause
- A wrong IP address in an A or AAAA record, or a routing problem on the way to the server
- First check
- Compare the address in the Cloudflare DNS records with the server's address
This error appears when a network device along the way doesn't know how to route traffic to the server's address. Make sure the A and AAAA records in Cloudflare contain the correct address, especially after a server move or an IP address change. If the address is correct, check with your server provider for a routing problem, and run MTR or traceroute from the server to a Cloudflare address.
-
Error 524
Response timed out- Meaning
- The connection was established, but the server didn't return an HTTP response in time
- Timeout
- 125 seconds by default (Proxy Read Timeout)
- Common cause
- A long request, such as a large export or a heavy query, or an overloaded server
Cloudflare waits 125 seconds for a response by default, and only on its Enterprise plan can this be extended to up to 6,000 seconds. Find the slow requests by logging response times in the server's access log, and then speed them up or split them: run a long process in the background, and have the page check its status every few seconds. Move operations that regularly take longer than 125 seconds, such as a large export, to a subdomain whose DNS record is set to DNS only (gray cloud).
-
Error 530
Server address not found- Meaning
- Cloudflare can't resolve the server's hostname, so it doesn't connect to it
- Error details
- A 1xxx code shown on the error page, for example 1016
This error appears together with a 1xxx code that gives the reason. With error 1016 (Origin DNS error), Cloudflare can't find the server's address, usually because the A record is missing or a CNAME record points to a domain that doesn't resolve. Make sure the A record points to a valid IP address, and that the domain the CNAME points to resolves in a DNS lookup.
SSL errors between Cloudflare and the server
-
Error 525
SSL handshake failed- Meaning
- The encrypted connection between Cloudflare and the server failed during the handshake
- When it appears
- Only in the Full and Full (strict) encryption modes
- Common cause
- No valid SSL certificate on the server, or port 443 is closed
Other causes are a server that doesn't support SNI, a mismatch between the server's cipher suites and those Cloudflare uses, and a key exchange compatibility requirement set in Cloudflare that the server doesn't support. Make sure a certificate is installed and the server accepts connections on port 443, test the certificate with a direct curl request to the server, and check the web server error log for what happened at the time of the error. If there's no certificate, install a Let's Encrypt certificate or a Cloudflare Origin CA certificate, which only Cloudflare trusts.
-
Error 526
Invalid SSL certificate on the server- Meaning
- Cloudflare can't validate the SSL certificate on the server
- When it appears
- In the Full (strict) encryption mode
- Common cause
- An expired certificate, a self-signed certificate, or one that doesn't include the domain name
In Full (strict) mode, the certificate on the server must be valid and not revoked, issued by a public certificate authority or by Cloudflare Origin CA, include the domain name in the Common Name or SAN, and be served together with the intermediate certificates. Renew or replace the certificate, and make sure the server accepts connections on port 443. Switching to Full mode makes the error go away, but then Cloudflare doesn't validate the certificate, so it's better to fix the certificate and stay on Full (strict).
Cloudflare encryption modes
-
Full (strict)
Recommended mode- Between Cloudflare and the server
- HTTPS, with validation of the server's certificate
- Certificate on the server
- A valid certificate from a public certificate authority, such as Let's Encrypt, or a Cloudflare Origin CA certificate
Cloudflare connects to the server using the same protocol the visitor used and validates the server's certificate, so the connection between Cloudflare and the server is encrypted and authenticated as well. This is the mode we recommend. Renew the certificate on time, because an expired certificate causes error 526. A Cloudflare Origin CA certificate is trusted only by Cloudflare, not by browsers, so it suits only records proxied through Cloudflare. No expiration alerts are sent for this certificate, so keep track of its expiration date yourself.
-
Full
Encryption without validation- Between Cloudflare and the server
- The same protocol the visitor used, without checking the certificate
- Certificate on the server
- Any certificate, even a self-signed or invalid one
When the visitor arrives over HTTPS, Cloudflare connects to the server over HTTPS but doesn't check the certificate. The traffic is encrypted, but nothing verifies that the connection reached the right server. When the server redirects HTTPS requests back to HTTP, a redirect loop occurs, so remove that redirect on the server.
-
Flexible
No encryption to the server- Between the visitor and Cloudflare
- HTTPS
- Between Cloudflare and the server
- HTTP only, unencrypted
The server doesn't need an SSL certificate, but traffic between Cloudflare and the server isn't encrypted. When the server or the site redirects every HTTP request to HTTPS, every Cloudflare request gets redirected again, and the browser shows ERR_TOO_MANY_REDIRECTS. The right fix is to install a certificate on the server and switch to Full (strict) mode.
-
Off
No encryption- Between the visitor and Cloudflare
- HTTP only
- Between Cloudflare and the server
- HTTP only
All traffic is unencrypted, both between the visitor and Cloudflare and between Cloudflare and the server.
-
Strict (SSL-Only Origin Pull)
Enterprise only- Between Cloudflare and the server
- Always HTTPS, with validation of the server's certificate
Cloudflare always connects to the server over an encrypted connection and validates the certificate as in Full (strict) mode, even when the visitor arrived over HTTP. This mode is available only on Cloudflare's Enterprise plan.
-
Automatic SSL/TLS
Default- What it does
- Chooses the most secure encryption mode the server supports
Cloudflare scans the site about once a month and gradually raises the encryption mode when the server supports a more secure one. It doesn't lower the mode on its own, so keep a valid certificate on the server after the upgrade as well.
Server checks and fixes
-
Direct request to the server, bypassing Cloudflare
curl- HTTP
- curl -svo /dev/null http://example.com --connect-to ::203.0.113.34
- HTTPS and certificate
- curl -svo /dev/null https://www.example.com --connect-to ::203.0.113.34
- Similar option
- curl -I --resolve www.example.com:443:203.0.113.34 https://www.example.com/
The request goes straight to the server's IP address with the site name, and shows whether the server itself returns an error, with which code, and which certificate it serves. Replace 203.0.113.34 with your server's address and example.com with your site name. If the server responds correctly to a direct request, check the firewall and the Cloudflare settings.
-
Cloudflare IP ranges
Firewall- Official list
- cloudflare.com/ips, separately for IPv4 and IPv6
- Updates
- Rarely. New ranges are added to the list before they go into use
Every request that passes through Cloudflare reaches the server from these ranges, so blocking them, even by mistake, stops your visitors. Allow all the ranges in the firewall, for example in UFW, firewalld, or CSF, and check the list from time to time. You can also block every non-Cloudflare address on ports 80 and 443, so anyone who discovers the server's address can't bypass the protections.
Official website Cloudflare IP ranges (opens in a new tab) -
fail2ban and CSF behind Cloudflare
Automatic blocking- fail2ban
- Cloudflare ranges in the ignoreip setting
- CSF
- Cloudflare ranges in csf.ignore, and allowed in the firewall in csf.allow
When the server doesn't restore the visitor's address, the access logs show Cloudflare addresses instead of visitor addresses. Software such as fail2ban or LFD may then block a Cloudflare address, and every visitor routed through it gets error 521 or 522. Restore the visitor's address in the logs, and add the Cloudflare ranges to the list of addresses that are never blocked.
-
The real visitor IP address
CF-Connecting-IP- Apache
- mod_remoteip with RemoteIPHeader CF-Connecting-IP and RemoteIPTrustedProxy for each range
- Nginx
- set_real_ip_from for each range and real_ip_header CF-Connecting-IP;
- LiteSpeed
- The Use Client IP in Header option in the server settings
Cloudflare adds the CF-Connecting-IP header with the visitor's address to every request. Configure the web server to read it on requests that come from Cloudflare ranges, so the logs, the site, and the security software see the real address. In Apache, also replace %h with %a in the log format.
-
Authenticated Origin Pulls
Only Cloudflare connects- Encryption modes
- Full and Full (strict) only
- Levels
- Global, per zone, or per hostname
Cloudflare presents a client certificate to the server on every connection, and the server accepts only connections that present it. That way, even someone who discovers the server's IP address can't bypass Cloudflare. With the global certificate, which all Cloudflare customers share, the server only knows the request came from Cloudflare, and with your own certificate it knows the request came from your account. When the option is on in Cloudflare and the server isn't set up to check the certificate, error 520 may appear.
-
Temporary test without the proxy
DNS only- How
- Set the DNS record to DNS only (gray cloud), or pause Cloudflare
If the error goes away when you browse directly to the server, the problem is in the connection between Cloudflare and the server. During the test, visitors reach the server directly, without Cloudflare's protections. When a Cloudflare Origin CA certificate is installed on the server, browsers show a security warning during this time, because only Cloudflare trusts it.
-
Ray ID and cdn-cgi/trace
Details for troubleshooting- Ray ID
- At the bottom of the error page and in the cf-ray response header
- trace
- https://www.example.com/cdn-cgi/trace
When you ask for help with an error, include the error code, the Ray ID, the time and time zone, and the full URL where the error appeared. A Ray ID isn't necessarily unique, so it's important to include the time of the request as well. The cdn-cgi/trace URL shows, in the colo field, the Cloudflare data center that handled the request.
No matching cards.
How to diagnose a Cloudflare error
- Start with the server: errors 520 to 526 describe a problem in the connection between Cloudflare and your site's server, so troubleshooting starts on the server, not in the visitor's browser.
- Direct request to the server: use curl to check the server's own response, by its IP address. If the direct request fails too, deal with the web server, the load, or the certificate.
- Logs at the time of the error: compare the time of the error with the web server error log and with the firewall, fail2ban, and LFD logs.
- DNS records: make sure the A and AAAA records in Cloudflare point to the server's current address.
- Encryption mode: check that the encryption mode in Cloudflare matches what the server supports, and prefer Full (strict) with a valid certificate.
With our Cloudflare services, we connect your domain to Cloudflare, set up the service for you, and copy all your existing DNS records, including your email records. You can add the service on the order form of our web hosting plans and VPS plans. On a Linux VPS, you have full root access, so you can allow Cloudflare's IP ranges in the firewall, install an SSL certificate to work in Full (strict) mode, and restore visitor IP addresses in the logs.
Cloudflare errors FAQ
What is the difference between Cloudflare error 521 and error 522?
With error 521, the server refused the connection from Cloudflare, usually because the web service is down or a firewall is blocking Cloudflare's addresses. With error 522, Cloudflare didn't get a response in time: it waits up to 19 seconds to establish the connection, and up to 90 seconds for data once the connection is established. In both cases, start by checking that the web server is running and that Cloudflare's IP ranges are allowed in the firewall.
Which Cloudflare encryption mode is recommended?
We recommend Full (strict) mode. In this mode, the connection between Cloudflare and the server is encrypted too, and Cloudflare verifies that the server's certificate is valid. A free Let's Encrypt certificate is enough, or a Cloudflare Origin CA certificate, which only Cloudflare trusts, not browsers. Flexible mode doesn't encrypt traffic to the server and can cause a redirect loop when the site redirects to HTTPS.
Why does my site get stuck in a redirect loop after connecting it to Cloudflare?
Usually the encryption mode is Flexible, and the site redirects every HTTP request to HTTPS. In Flexible mode, Cloudflare connects to the server over HTTP, the server returns a redirect to HTTPS, and the cycle repeats until the browser shows ERR_TOO_MANY_REDIRECTS. The fix is to install an SSL certificate on the server and switch to Full (strict) mode.
How do I see visitors' real IP addresses behind Cloudflare?
Cloudflare passes the visitor's address in the CF-Connecting-IP header. Configure the web server to read this header on requests that come from Cloudflare ranges: in Apache with mod_remoteip, in Nginx with set_real_ip_from and real_ip_header, and in LiteSpeed with the Use Client IP in Header option. From then on, the real addresses appear in the logs, on the site, and in the security software.
Can you connect my site to Cloudflare for me?
Yes. With our Cloudflare services, we connect your domain, set up the service, and copy all your existing DNS records, including your email records. You can add the service on the order form of our web hosting plans and VPS plans.