Quick Triage Matrix

Cloudflare 5xx Error Comparison at a Glance

Each error represents a breakdown at a specific layer of the network stack between Cloudflare's edge proxy and your origin server:

Error CodeOfficial Status NameFailure LayerUnderlying Root CauseImmediate Sysadmin Triage
520Web Server Returns an Unknown ErrorHTTP Response StreamOrigin returned an empty, unknown, or unexpected response (Cloudflare lists crashes, malformed responses, and headers over 128 KB, among others).Inspect origin error logs; check response header size and HTTP/2 configuration.
521Web Server Is DownTCP SYN / Port ListeningOrigin web server refused connections from Cloudflare (offline web server application or blocked Cloudflare requests).Verify daemon is running (systemctl status nginx) and bound to 0.0.0.0.
522Connection Timed OutTCP 3-Way HandshakeNo SYN+ACK within 19 s, or no ACK of the request within 90 s after connecting. Most common cause per Cloudflare: Cloudflare IPs rate limited or blocked.Ensure all Cloudflare IP ranges are allowlisted in origin firewall and security groups.
524A Timeout OccurredHTTP Request ExecutionConnection succeeded, but the origin did not respond before the Proxy Read Timeout (default 125 s).Identify long-running database queries, slow API calls, or worker pool starvation.
502Bad GatewayUpstream Gateway / FastCGIA gateway received an invalid response from an inbound server (RFC 9110). Cloudflare-branded 502/504 pages come from the origin.Check PHP-FPM / Node / Python socket availability and NGINX error.log.

Architecture & Topology

The 4-Tier Packet Flow: Where Connections Drop

To quickly troubleshoot 5xx outages, you must understand which network hop broke down. Cloudflare operates as a reverse proxy sitting between visitor web browsers and your origin infrastructure:

NETWORK TOPOLOGY: Cloudflare Edge to Origin BackendHop-by-Hop Breakdown
TIER 1

Client Browser

User Agent (Chrome, Safari, cURL, Mobile App)

TLS 1.3 / HTTP/2 or HTTP/3
✓ Client → Cloudflare OK
TIER 2

Cloudflare Edge

Anycast POPs, WAF, CDN Cache, DDoS Shield

Generates 5xx when:
• Connection Refused: 521
• Connection Timeout: 522
• Read Timeout (default 125 s): 524
• Unknown/Empty Response: 520
TIER 3

Origin Server

Firewall (iptables/UFW), NGINX/Apache Reverse Proxy

Listens on 80/443
Firewall Drops → 522
Service Down → 521
TIER 4

Upstream App

PHP-FPM, Node.js, Python WSGI, PostgreSQL

FastCGI / Unix Socket
Socket Crash → 502
Slow Response → 524
[Client Browser]
       │
       ▼  HTTPS (TCP 443 / TLS 1.3)
[Cloudflare Edge Anycast POP]
       │
       ├─── [TCP SYN] ───────────────────► [Origin Firewall / iptables]
       │                                            │
       │                                     DROPPED by iptables/UFW
       │                                            ▼
       │ ◄─── (No SYN+ACK within 19s) ─────── ❌ ERROR 522 Connection Timed Out
       │
       ├─── [TCP SYN] ───────────────────► [Origin Port 80/443]
       │                                            │
       │                                     NO DAEMON LISTENING
       │                                            ▼
       │ ◄─── [TCP RST / Connection Refused] ❌ ERROR 521 Web Server Is Down
       │
       ├─── [HTTP GET] ──────────────────► [Origin NGINX Web Server]
       │                                            │
       │                                     EXECUTES BACKEND SCRIPT
       │                                            ▼
       │                                   [PHP-FPM / Node / Database]
       │                                            │
       │                              No response before read timeout (default 125s)
       │                                            ▼
       │ ◄─── (Edge Gateway Timeout) ──────── ❌ ERROR 524 A Timeout Occurred
       │
       ├─── [HTTP GET] ──────────────────► [Origin Web Server]
       │                                            │
       │                                     EMITS EMPTY / CORRUPT DATA
       │                                            ▼
       │ ◄─── [Empty / malformed / headers >128KB] ❌ ERROR 520 Web Server Returns Unknown
       │
       └─── [HTTP GET] ──────────────────► [Origin NGINX]
                                                    │
                                             Proxy pass to unix socket
                                                    ▼
                                           [Upstream App CRASHED]
                                                    ▼
                                           ❌ ERROR 502 Bad Gateway

Technical Breakdown

Granular Analysis by Cloudflare Status Code

Status 520 · HTTP Response StreamMalformed Response

Error 520: Web Server Returns an Unknown Error

Cloudflare's documentation: "This error occurs when the origin server returns an empty, unknown, or unexpected response to Cloudflare."

Causes Cloudflare lists for 520 (source):

  • Origin crashes or misconfigurations, for example a web server or application process that dies mid-response.
  • Firewalls or security plugins blocking Cloudflare IPs at your origin.
  • Headers exceeding 128 KB, often due to excessive cookies.
  • Empty or malformed responses lacking an HTTP status code or response body, or missing response headers.
  • Incorrect HTTP/2 configuration at the origin server.
  • Authentication Origin Pull enabled on Cloudflare when the origin is not configured for it.
Sysadmin Verification Command:
curl -svo /dev/null -H "Host: example.com" https://ORIGIN_IP/ 2>&1 | grep -E "(Connected|HTTP\/|Closing connection)"
Status 521 · Port Connection RefusedService Down

Error 521: Web Server Is Down

Cloudflare's documentation: "Error 521 occurs when the origin web server refuses connections from Cloudflare." The two most common causes it names are an offlined origin web server application and blocked Cloudflare requests.

What to check (Cloudflare causes, plus common server checks):

  • Web server application offline: NGINX, Apache, Caddy, or IIS is not running. Check its error logs for crashes or outages.
  • Blocked Cloudflare requests: Cloudflare says to "allow all Cloudflare IP ranges in your origin web server's firewall or other security software."
  • Listening on the wrong interface (common server check): The web server is configured to listen on 127.0.0.1:443 instead of the public network interface or wildcard 0.0.0.0:443.
  • Port or SSL mode mismatch: Cloudflare says the origin must listen on "Port 80 for Flexible, or Port 443 for Full and Full (Strict)," and must support HTTPS with a valid certificate in Full or Full (Strict) mode.
Sysadmin Verification Commands:
sudo systemctl status nginx
sudo ss -tulpn | grep -E ':(80|443)'
Status 522 · Connection TimeoutPacket Dropped

Error 522: Connection Timed Out

Cloudflare's documentation: "Error 522 occurs when Cloudflare times out contacting the origin web server." It describes two timeouts: no SYN+ACK within 19 seconds of sending a SYN, or, after the connection is established, no acknowledgment (ACK) of the request within 90 seconds.

Causes Cloudflare lists for 522 (source):

  • Cloudflare IPs rate limited or blocked in .htaccess, iptables, or firewalls. Cloudflare calls this the most common cause.
  • Origin IP mismatch: the origin IP in Cloudflare DNS does not match the IP your hosting provider currently assigns.
  • Keepalives disabled at the origin web server, or packets dropped at the origin.
  • Overloaded or offline origin dropping incoming requests.
Sysadmin Remediation: Allowlist Cloudflare IP Prefixes
# Check active iptables DROP rules
sudo iptables -L INPUT -v -n | grep DROP
# Ensure all ranges from https://www.cloudflare.com/ips/ are ACCEPTED
Status 524 · Proxy Read TimeoutExecution Timeout

Error 524: A Timeout Occurred

Cloudflare's documentation says a 524 occurs when Cloudflare connected to the origin but the origin did not respond before the Proxy Read Timeout, 125 seconds by default. Enterprise customers can increase the 524 timeout up to 6,000 seconds (per cacheable path with a Cache Rule, or zone-wide through the API).

Typical reasons an origin responds too slowly (editorial examples):

  • Long-Running Database Queries: Heavy data exports, table scans, or unindexed JOIN operations holding synchronous HTTP worker threads.
  • PHP-FPM Worker Starvation: All available PHP-FPM children (pm.max_children) are occupied, placing incoming requests in an indefinite queue.
  • Synchronous File Processing: Uploading, compressing, or watermarking large media files directly inside the web request lifecycle instead of delegating to asynchronous queues (e.g., Redis, Celery, BullMQ).
Architectural Fix:
Cloudflare recommends status polling for large HTTP jobs, moving long-running requests (such as large exports) to a DNS-only subdomain, and asking your host to check for long-running processes or an overloaded origin. One common pattern: return HTTP 202 Accepted with a job-status URL the client can poll.
Status 502 · RFC 9110 Bad GatewayUpstream Crash

Error 502: Bad Gateway (Origin vs Cloudflare)

RFC 9110 §15.6.3: "The 502 (Bad Gateway) status code indicates that the server, while acting as a gateway or proxy, received an invalid response from an inbound server it accessed while attempting to fulfill the request." Cloudflare's 502/504 documentation separates two cases by how the error page looks:

Cloudflare-branded 502/504 page

Cloudflare says: "If the error page is Cloudflare-branded, the 502 or 504 came from your origin web server instead." Contact your hosting provider; check whether the origin responds for the hostname, and look for load spikes, crashes, or network failures.

Blank, unbranded 502/504 page

Cloudflare describes this as a Cloudflare-side error. Its likely cause is a compression issue at the origin, such as a wrong content-length on gzip content; Cloudflare suggests disabling compression at the origin to test. On your own server, a reverse proxy that cannot reach its application (for example, connect() to unix:/var/run/php/php-fpm.sock failed) also produces a 502.

Check NGINX Error Log for Upstream Socket Failures:
sudo tail -n 50 /var/log/nginx/error.log | grep -E "(connect\(\) failed|upstream prematurely closed)"

Interactive Decision Tree

Step-by-Step Sysadmin Triage Checklist

A practical checklist for a Cloudflare 5xx outage. Steps 2–4 are general server-administration checks, not Cloudflare instructions:

  1. Step 1: Record the Error Details

    Note the exact error code, the Ray ID shown on the Cloudflare error page, the time with timezone, and the failing URL. Cloudflare's 502/504 documentation asks for the timestamp, the failing URL, and the output of <YOUR_DOMAIN>/cdn-cgi/trace when you contact support.

  2. Step 2: Bypass Cloudflare Using Direct cURL to Origin IP

    Run this command from your local terminal to isolate the origin from Cloudflare:

    curl -svo /dev/null -H "Host: yourdomain.com" https://ORIGIN_SERVER_IP/

    • If this returns HTTP 200 OK, your origin server is answering; look at the Cloudflare-to-origin path, such as a firewall blocking Cloudflare IPs (522) or an SSL mode mismatch.
    • If this returns Connection refused, your web server is stopped (521).
    • If this times out, your server network interface is down or dropping traffic.

  3. Step 3: Check System Resource Saturation

    SSH into the origin server and inspect CPU, RAM, and load averages:

    uptime && free -m && dmesg -T | grep -i oom

    If the Linux kernel's Out-Of-Memory (OOM) killer recently terminated PHP-FPM, MySQL, or NGINX processes, you will see kernel kill events in dmesg.

  4. Step 4: Verify Origin Firewall Allowlist

    Ensure your hosting provider security groups, AWS VPC Network ACLs, and host-level firewalls allow incoming traffic on ports 80 and 443 from all official Cloudflare IP blocks:

    curl -s https://www.cloudflare.com/ips-v4 && curl -s https://www.cloudflare.com/ips-v6

Frequently Asked Questions

Cloudflare 5xx Triage FAQs

What is the fundamental difference between Cloudflare 522 and 524 errors?

A 522 (Connection timed out) means Cloudflare timed out contacting the origin. Cloudflare's documentation says this happens when it does not receive a SYN+ACK within 19 seconds of sending a SYN, or, after the connection is established, does not receive an acknowledgment (ACK) of its request within 90 seconds. A 524 (A timeout occurred) means Cloudflare connected to the origin, but the origin did not send a response before the Proxy Read Timeout, which Cloudflare documents as 125 seconds by default. Enterprise customers can raise the 524 timeout up to 6,000 seconds. We checked these figures against Cloudflare documentation on October 11, 2026; Cloudflare can change them.

Why does Cloudflare return Error 520 instead of a standard HTTP 500 or 502?

Cloudflare documents 520 as the error it returns when "the origin server returns an empty, unknown, or unexpected response to Cloudflare." Causes it lists include origin crashes or misconfigurations, firewalls or security plugins blocking Cloudflare IPs, headers exceeding 128 KB (often from excessive cookies), empty or malformed responses lacking an HTTP status code or body, missing response headers, incorrect HTTP/2 configuration at the origin, and Authentication Origin Pull enabled on Cloudflare without matching origin configuration.

How can I verify whether an error is coming from Cloudflare or my origin server?

For 502 and 504 errors, Cloudflare's documentation uses page branding: if the error page is Cloudflare-branded, the 502 or 504 came from your origin web server, so contact your hosting provider. If it is a blank page without Cloudflare branding, Cloudflare points to a likely compression issue at the origin, such as a wrong content-length on gzip content. You can also request your origin directly (bypassing Cloudflare) to see whether the origin itself responds. When contacting Cloudflare Support, Cloudflare asks for the timestamp with timezone, the failing URL, and the output of <YOUR_DOMAIN>/cdn-cgi/trace.

How do I bypass Cloudflare using cURL to test my origin server directly?

Use cURL's '--resolve' flag or an explicit Host header to send the request directly to your origin web server's public IP address instead of through Cloudflare: 'curl -svo /dev/null -H "Host: yourdomain.com" https://ORIGIN_SERVER_IP/'. Alternatively, use: 'curl -svo /dev/null --resolve yourdomain.com:443:ORIGIN_SERVER_IP https://yourdomain.com/'. If the origin answers normally this way, look at the path between Cloudflare and the origin (for example, a firewall blocking Cloudflare IP ranges). If it fails or times out, start with the origin server itself.

Why does my origin server firewall block Cloudflare IPs causing 522 errors?

Cloudflare's 522 documentation names Cloudflare IP addresses being "rate limited or blocked in .htaccess, iptables, or firewalls" as the most common cause. Because proxied traffic reaches your origin from Cloudflare's IP ranges rather than from each visitor's address, rate-limiting or intrusion-prevention tools at the origin can end up blocking those ranges. Allow Cloudflare's published IPv4 and IPv6 ranges (cloudflare.com/ips) in your origin firewall and hosting security rules.

Authority Citations

Primary Sources & Standards

Definitions, timeouts, and limits on this page come from the documents below (source checked October 11, 2026). Cloudflare updates its documentation; confirm current values on the live pages. Server commands and the packet-flow diagram are editorial illustrations.

Spotted an outdated specification or cloud provider documentation change? Report a correction ↗

Related HTTP & Diagnostic Resources