All ArticlesDevOps2026-11-12T11:14:02+08:00

Cloudflare 503 but Origin Is Healthy? Read cf-ray and cf-cache-status Headers to Find the Fault

Your site returns 503 errors through Cloudflare even though the origin server responds fine to direct requests. After reading this postmortem teardown you will know how to use cf-ray, cf-cache-status, and edge response headers to pinpoint whether the failure is at the edge PoP, the origin pull, or a Worker in between.

Your site throws 503 errors for visitors, but when you curl the origin IP directly, it responds fine. The monitoring dashboard is green, Apache or Nginx is running, PHP-FPM has workers available. Everything looks healthy except the part that matters: what users actually see through Cloudflare. This disconnect is common, and the response headers Cloudflare attaches to every request tell you exactly where the failure sits, if you know how to read them.

This article walks through the investigation pattern as a postmortem: what the symptoms look like, how to narrow down the fault layer, and what fixes apply depending on what the headers reveal.

Initial impact: 503 for visitors, 200 for you

The typical report goes like this: users complain the site is down, you SSH into the server, run curl -I http://localhost or hit the origin IP directly, and get a clean 200 OK. You check process lists, disk space, load average, all normal. The confusion comes from assuming that if the origin works, Cloudflare should too.

But a request through Cloudflare passes through at least two layers before reaching your server: the edge PoP (Point of Presence, the Cloudflare data center closest to the visitor) and the origin pull (Cloudflare connecting back to your server). If you use Cloudflare Workers, there is a third layer. A 503 can originate at any of these points, and the error page itself plus the response headers tell you which one.

First check: who generated the 503 page?

Before touching headers, look at the HTML body of the 503 response. This is the single fastest way to split the problem in half.

According to Cloudflare's own troubleshooting documentation, if the error page HTML contains "cloudflare" or "cloudflare-nginx" in the server identification, the 503 was generated by Cloudflare itself, typically due to a routing or connectivity issue inside Cloudflare's network, or because your origin is blocking Cloudflare's connections. If the error page does NOT contain Cloudflare branding, your origin server generated the 503 and Cloudflare is just passing it through.

You can check this without a browser:

curl -sD - https://example.com | head -50

Look at both the server response header and the HTML body. A server: cloudflare header combined with Cloudflare-branded error HTML means the edge or the origin pull failed. A server: cloudflare header but with your origin's error page (Apache's default 503, Nginx's own error template, or your custom error page) means the origin returned 503 and Cloudflare relayed it.

Reading cf-ray to identify the edge PoP

Every response through Cloudflare includes a cf-ray header. It looks something like this:

cf-ray: 8a1b2c3d4e5f6-SIN

The hex string is a unique request identifier. The three-letter code at the end is the IATA airport code of the Cloudflare PoP that handled the request. SIN means Singapore, LAX means Los Angeles, CGK means Jakarta.

Why this matters during a 503 investigation:

  • If all failing requests share the same PoP code, the problem might be isolated to that specific edge location or the network path between that PoP and your origin. Cloudflare has had incidents where individual PoPs experienced issues while the rest of the network was fine.
  • If failing requests come from multiple different PoPs, the problem is almost certainly on the origin side or in a Worker that runs globally.
  • The cf-ray value is what Cloudflare support needs if you open a ticket. Without it, they cannot trace the request through their systems.

Collect a few cf-ray values from different geographic locations (ask a colleague in another region, or use a tool that lets you specify the request origin) and compare the PoP codes.

Reading cf-cache-status to understand the request path

The cf-cache-status header tells you what Cloudflare's cache layer did with the request. During a 503 investigation, this header reveals whether Cloudflare even attempted to reach your origin.

Common values you will see:

ValueWhat it means for your investigation
DYNAMICRequest was not cacheable. Cloudflare forwarded it to origin. If you got a 503 with this status, the origin pull failed or origin returned 503.
MISSCacheable but not in cache. Cloudflare went to origin. Same implication as DYNAMIC for a 503.
HITServed from cache. You should NOT see a 503 with a HIT, because cached content would be served. If you do, something unusual is happening.
BYPASSCache was deliberately skipped (by a Page Rule, Cache Rule, or Worker). Cloudflare went to origin.
EXPIREDCache entry existed but expired. Cloudflare went to origin for a fresh copy.

If the 503 response has cf-cache-status: DYNAMIC or MISS, Cloudflare tried to reach your origin and either could not connect or received a 503 back. This narrows the investigation to the origin pull path.

The critical discovery: origin firewall blocking Cloudflare IPs

The most common cause of "origin healthy but 503 through Cloudflare" is the origin server's firewall blocking Cloudflare's IP addresses. This happens more often than people expect.

Cloudflare connects to your origin from a known set of IP ranges. If your server runs a firewall like csf (ConfigServer Security & Firewall), Fail2ban, cpHulk, ModSecurity, or even basic iptables/nftables rules with connection rate limits, those tools can flag Cloudflare's IPs as abusive. From the firewall's perspective, a single IP range is making hundreds of connections per minute, which looks like an attack.

The pattern: site works fine for a while after a server restart or firewall flush, then starts returning 503 after the firewall accumulates enough "violations" from Cloudflare IPs to trigger a block.

To check, look at your firewall's deny log. For csf:

grep -i deny /var/log/lfd.log | head -20

Compare any blocked IPs against Cloudflare's published IP ranges (available at cloudflare.com/ips). If you see matches, that is your problem.

The fix: whitelist all Cloudflare IP ranges in your firewall. If you use rate limiting on your web server, make sure the rate limit evaluates the visitor's real IP (passed in the CF-Connecting-IP or X-Forwarded-For header) rather than Cloudflare's edge IP. Otherwise, all visitors behind a single PoP look like one client, and legitimate traffic triggers the rate limit. For more on rate limiting configuration, see Rate Limiting xmlrpc.php to Prevent Recurring Server Load Spikes, which covers how to set up rate limits that work correctly behind a reverse proxy.

Other fault layers: Workers and origin pull timeouts

If the firewall is clean and the origin genuinely responds 200 to direct requests, two other layers can produce 503s:

Cloudflare Workers. If you have a Worker deployed on the route, an unhandled exception in the Worker script can return an error to the visitor. Worker errors sometimes show as 1101 (Worker threw an exception) rather than 503, but misconfigured Workers that attempt to fetch from the origin and fail on timeout or bad URL construction can produce 503. Check if any Workers are deployed on the affected route in the Cloudflare dashboard. Temporarily disable the Worker to isolate.

Origin pull timeouts. Cloudflare has a default timeout for connecting to and receiving a response from your origin. If your origin is technically "up" but responding slowly (a PHP script taking too long, a database query hanging, a full PHP-FPM pool), Cloudflare may time out waiting and return a 524 (a timeout) or in some configurations a 503. Check your origin's response time for the specific URLs that are failing, not just the homepage. A healthy homepage does not mean /wp-admin/admin-ajax.php is responding within acceptable time.

Temporary mitigation

While investigating, a few things buy time:

  1. If the problem is firewall-related, flush the blocked IPs and whitelist Cloudflare ranges immediately.
  2. If a Worker is suspect, disable it or add a try/catch that returns a meaningful error instead of crashing.
  3. If the origin is slow on specific paths, enable Cloudflare's "Always Online" feature (if available on your plan) to serve stale cached copies while you fix the origin. This only helps for previously cached pages.
  4. Use "Development Mode" in Cloudflare to bypass caching entirely, which does not fix a firewall block but helps isolate cache-related issues.

The architectural fix

The lasting fix depends on which layer failed, but the common thread is: do not treat Cloudflare as a transparent passthrough that needs no configuration on the origin side.

Whitelist Cloudflare IPs permanently in every firewall layer on your origin. Automate this. Cloudflare's IP list can change, so set up a cron job or script that periodically pulls the current list and updates your firewall rules.

Restore real visitor IPs in your web server configuration so that rate limiting, logging, and security tools evaluate the actual client IP, not Cloudflare's edge IP. Apache has mod_remoteip, Nginx has set_real_ip_from, and LiteSpeed has its own trusted proxy configuration.

Monitor the origin pull path, not just the origin itself. A health check that curls localhost proves the process is running. It does not prove that Cloudflare can reach port 443 on your public IP through your firewall. Set up an external monitor that hits the URL through Cloudflare and alerts on non-200 responses.

Log cf-ray on the origin. Add $http_cf_ray (Nginx) or the equivalent to your access log format. When a user reports a 503 and gives you the cf-ray value, you can check whether that request ever reached your origin. If it is absent from origin logs, the connection died between Cloudflare and your server.

The headers Cloudflare attaches to every response are not decorative. cf-ray tells you where, cf-cache-status tells you how the request was handled, and the error page branding tells you who generated the error. Check all three before assuming the problem is on Cloudflare's side or yours. Most of the time, the origin is not as healthy as it looks from the inside.