Skip to content
Tutorials Center
My learning

Topics

Lesson 32 of 36 ยท Operations and Analytics

Cloudflare Limits, Costs and Troubleshooting Errors

Diagnose common Cloudflare errors (520 to 526, 1000-series, Worker 1101), understand plan limits and costs, and follow a step-by-step troubleshooting method with a runnable error lookup.

Sooner or later a visitor sees a Cloudflare error page, a bill surprises you, or a deploy hits a limit. The skill is not memorizing every code; it is knowing which side of the proxy produced the problem and what to check first. This lesson gives you that method, the most common errors and the cost levers.

Cloudflare dashboards and error pages are Cloudflare's, so this lesson is descriptive. The runnable parts are a lookup table and a diagnosis helper.

Step one: whose error is it?

Every request has three hops: visitor, Cloudflare, your origin. The first question is where the failure happened.

flowchart LR
  V["Visitor"] -->|"1"| CF["Cloudflare edge"]
  CF -->|"2"| O["Your origin"]
  CF -.->|"error page branded Cloudflare = edge problem"| V
  O -.->|"error from your server passed through = origin problem"| CF

Look at the error page and the response headers: cf-ray is present on everything Cloudflare served, and server: cloudflare appears on both edge-generated and passed-through responses.

Two habits help immediately:

  1. Record the Ray ID (cf-ray header and the number on error pages). Cloudflare support and your own logs use it to find the exact request.
  2. Compare with and without the proxy. Temporarily request the origin directly (using its IP and a Host header, or a grey-clouded hostname) to see whether the origin itself works.

The 5xx errors you will actually meet

Code Meaning in practice First checks
520 Origin returned something Cloudflare could not understand (empty or malformed response, crash, oversized headers) Origin error logs; headers too big; app crashes
521 Origin refused the connection Is the web server running? Is Cloudflare allowed by the firewall?
522 Connection to the origin timed out Firewall dropping Cloudflare IPs; origin overloaded; wrong IP in DNS
523 Origin unreachable DNS record points to a wrong or private IP; routing
524 Connection worked but the origin took too long to answer (about 100 seconds by default) Slow request; move long work to a queue or background job
525 TLS handshake with the origin failed Origin has no valid certificate/cipher for Cloudflare, or SSL mode mismatch
526 Origin certificate invalid in Full (strict) mode Expired, self-signed or wrong-hostname certificate; use a Cloudflare Origin CA certificate
502 / 504 Bad gateway / gateway timeout: the origin (or a proxy before it) failed Often the origin app; check Cloudflare vs origin logs
403 (Cloudflare page) A security rule blocked the request Security Events: which rule fired?
429 Rate limited by a rule Rate limiting rules, or the API's own limits

Common 1xxx errors

  • 1000-series DNS errors (for example 1001, 1002): the hostname's DNS points to something invalid or a Cloudflare-only IP.
  • 1015: you are being rate limited by a rate limiting rule.
  • 1020: access denied, a firewall/WAF rule matched.
  • 1101 (Worker threw an exception) and 1102 (Worker exceeded CPU/memory): look at wrangler tail, fix the exception or reduce the work.
  • 1042: a Worker tried to fetch another site in the same zone in a way that is not allowed; use a service binding or fetch the origin directly.

SSL/TLS mode mismatches

The classic loop and handshake problems come from the SSL mode:

  • Flexible (visitor to Cloudflare encrypted, Cloudflare to origin plain HTTP): can cause redirect loops if the origin redirects HTTP to HTTPS. Prefer a real certificate.
  • Full accepts any origin certificate; Full (strict) requires a trusted one (a free Cloudflare Origin CA certificate counts).
  • Set Full (strict) for anything serious, and install an origin certificate to make it work.

A diagnosis helper

This lookup turns a status code and a few facts into a likely cause and the first thing to check. It is a teaching aid, not a replacement for logs.

JS Error code lookup and first check

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Plan limits worth knowing

Limits depend on the plan and change over time; always confirm them in the documentation before relying on them. Typical limits that bite:

  • Upload size: the proxy limits request bodies on lower plans (about 100 MB on Free and Pro). For large files use R2 with presigned URLs.
  • Origin timeout: roughly 100 seconds before a 524 on most plans.
  • Cache file size: individual cacheable objects are limited; video streaming through the proxy requires the right product.
  • Workers: CPU time, memory, subrequests per request and bundle size, plus a daily request cap on the free plan.
  • Rules: a maximum number of rules per product (WAF custom rules, redirects, cache rules) per plan.
  • DNS: record count and zone limits.

Where the money goes

Cloudflare's pricing is mostly predictable, but these parts scale with use:

  • Plan fees per zone (Free, Pro, Business, Enterprise).
  • Workers: requests and CPU time beyond the included amount.
  • R2: stored GB and operations (no egress).
  • KV and D1: reads, writes and (for D1) rows read and written plus storage.
  • Zero Trust: per user per month on paid plans.
  • Add-ons: advanced rate limiting, bot management, load balancing, image transformations, Stream and more are priced separately.

To keep bills sane, set billing notifications and usage alerts, cache aggressively so Workers and origins do less, index D1 queries to limit rows read, and review usage monthly.

JS Estimate a Worker + D1 month (example prices)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The comparison makes the point: a missing index changes rows read by orders of magnitude, so it changes the bill, not just the speed.

A troubleshooting checklist

  1. Reproduce and note the status code, URL, time and Ray ID.
  2. Decide edge or origin: branded Cloudflare error page versus your app's own page.
  3. Check Security Events for blocks, and Analytics for spikes or changes.
  4. Check recent changes: a rule, a Worker deploy, a DNS edit, a certificate renewal. The audit log lists who changed what.
  5. Test the origin directly and compare responses.
  6. Look at logs (origin logs, wrangler tail, Logpush).
  7. Roll back the last change if it correlates (wrangler rollback, disable the rule), then investigate calmly.
  8. Contact support with the Ray ID, a timeline and what you ruled out.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Your site shows error 522. What is the most likely area to investigate?

    522 means the connection to the origin timed out. Firewalls, overloaded servers and wrong IPs are the usual causes.
  2. 2. What does error 526 indicate?

    526 appears when strict mode cannot validate the origin certificate; install a valid or Cloudflare Origin CA certificate.
  3. 3. Why record the Ray ID?

    The cf-ray value points to one request, so logs and support can find precisely what happened.
  4. 4. Which change most reduces D1 read costs for a hot query?

    D1 charges per row read, and an index lets SQLite read a handful of rows instead of scanning the table.

Summary

  • First decide whether a failure is at the edge or at the origin; always capture the Ray ID.
  • 520 to 526 describe origin connection and TLS failures; 1020 and 1015 are security or rate rules; 1101 and 1102 are Worker faults.
  • Use Full (strict) SSL with an origin certificate to avoid loops and handshake errors.
  • Know the limits (upload size, origin timeout, Worker CPU, rule counts) and the cost levers (cache, indexes, usage alerts).
  • Follow a checklist: reproduce, locate, check rules and recent changes, test the origin, read logs, roll back, escalate with evidence.

Next: Project: A URL Shortener on Workers, KV and D1