Why CDN Configuration Errors Happen (and How to Think About Them)
Content Delivery Networks (CDNs) sit between your users and your origin servers. They cache content, terminate TLS, rewrite headers, block attacks, and accelerate delivery. When something goes wrong, it often manifests as cryptic error pages, inconsistent behavior, or slow performance—yet the root cause can be anywhere across DNS, TLS, edge configuration, cache rules, origin connectivity, or security policies.
Mastering CDN troubleshooting means methodically isolating each layer. This guide shows you how to diagnose and fix common configuration errors in Cloudflare and AWS CloudFront, with practical steps, command examples, and configuration snippets you can apply immediately.
A Fast Triage Checklist
Before deep-diving, run this quick triage to classify the issue and narrow your search:
- Scope
- Is the issue global or region-specific?
- Does it affect all paths or specific endpoints/assets?
- Does it affect only some users, devices, or ISPs?
- Reproducibility
- Reproducible consistently or intermittent?
- Only on first request (cache miss) or also on subsequent requests (cache hit)?
- Signals (via browser DevTools or curl)
- Check response headers: CF-Cache-Status (Cloudflare), X-Cache (CloudFront), Age, Via, Server.
- Error pages: Look for Cloudflare Ray ID or CloudFront request ID.
- Quick toggles
- Pause Cloudflare proxy (gray-cloud) or bypass cache to isolate origin vs edge.
- In CloudFront, hit the origin directly to eliminate CDN effects.
Once you know where the problem lives—DNS, TLS, cache, origin, or security—you can fix it decisively.
Your Troubleshooting Toolkit
- CLI and network tools
- curl -I https://example.com — inspect headers/status without downloading the body.
- curl -svo /dev/null https://example.com — verbose TLS and negotiation.
- dig/host/nslookup — verify DNS records and propagation.
- traceroute/mtr — identify network path issues.
- Browser DevTools
- Network waterfall, response headers, mixed content warnings, CORS preflight errors.
- CDN metrics and logs
- Cloudflare: CF-Ray, CF-Cache-Status, Logpush, Analytics.
- CloudFront: X-Amz-Cf-Id, X-Amz-Cf-Pop, X-Cache, standard/access logs, real-time logs (Kinesis).
- Observability
- RUM for real-user metrics; synthetic checks from multiple regions.
- Error monitoring with unique request IDs.
Common Error Categories and How to Fix Them
1) DNS and Domain Mapping Issues
Symptoms:
- Domain not resolving, or resolves to wrong IP.
- SSL/TLS handshake failures after adding a CNAME.
- Random 404 on CDN but origin works.
Cloudflare
- Ensure your DNS record is proxied (orange cloud) when you want Cloudflare protection. Use DNS-only (gray cloud) to test direct origin behavior.
- For apex domains (example.com), use A/AAAA to your origin or Cloudflare’s proxied A/AAAA/ALIAS-like behavior. Do not CNAME apex unless your DNS provider supports ANAME/ALIAS; Cloudflare’s DNS handles apex properly under proxy.
- If moving DNS, confirm NS records at your registrar match Cloudflare’s nameservers. Propagation can take up to 48 hours.
- Validate the CNAME chain resolves correctly and isn’t pointing to a CloudFront distribution unintentionally.
CloudFront
- Add your custom domain under Alternate Domain Names (CNAMEs).
- Attach an ACM certificate issued in us-east-1 (N. Virginia) that covers your domain and any wildcard needed.
- DNS: point the domain CNAME to your CloudFront distribution domain (d1234.cloudfront.net). For apex, use Route 53 alias (A record alias to CloudFront).
Verification
- dig +short example.com
- curl -I https://example.com
- Ensure the correct certificate is served and the CDN hostname matches.
2) SSL/TLS Mode and Certificate Mismatches
Symptoms:
- Cloudflare error 525 (SSL handshake failed) or 526 (Invalid SSL certificate).
- CloudFront ERR_SSL_VERSION_OR_CIPHER_MISMATCH or certificate name mismatch.
- Redirect loops to HTTPS.
Cloudflare
- Avoid Flexible SSL. It terminates HTTPS at the edge but connects to the origin over HTTP, often causing redirect loops. Prefer Full (Strict).
- Full (Strict) requires a valid certificate at the origin. Use:
- Public CA certificate (LetsEncrypt) or
- Cloudflare Origin Certificate installed on your server.
- Under SSL/TLS → Edge Certificates, ensure Universal SSL is active. If using custom certs, check expiration and hostnames.
- Use “Always Use HTTPS” at the edge only if the origin won’t also redirect HTTP to HTTPS (to avoid loops). If origin redirects, keep Cloudflare set to Full (Strict) and disable redundant edge redirects.
CloudFront
- Attach an ACM certificate in us-east-1. Ensure SANs cover all alternate domain names.
- Set Viewer Protocol Policy to Redirect HTTP to HTTPS (recommended) to enforce HTTPS at the edge cleanly.
- If your origin is HTTPS:
- Origin Protocol Policy: HTTPS only (or Match Viewer if needed).
- If your origin requires SNI, confirm “Origin SNI” is enabled and hostname is correct.
- Cipher policies: choose a modern security policy (e.g., TLSv1.2_2021) unless legacy clients need older ciphers.
Quick checks
- curl -svo /dev/null https://example.com — verify SNI hostname, ALPN, and certificate chain.
- For Cloudflare error 526: ensure origin certificate is trusted (Full Strict) and covers the domain.
3) Origin Connectivity and Timeouts
Symptoms:
- Cloudflare 521 (Web server is down), 522 (Connection timed out), 523 (Origin unreachable), 524 (Timeout).
- CloudFront 504 Gateway Timeout, or X-Cache: Error from cloudfront.
- Intermittent 5xx errors under load.
Cloudflare
- Verify origin firewall/ACL allows Cloudflare IP ranges. Origin should never see client IPs directly; it will see Cloudflare egress IPs.
- Action: Allowlist Cloudflare IP ranges in your firewall or reverse proxy.
- Ensure the origin port is open (typically 443/80); Cloudflare limits supported ports. If using a non-standard port, verify Cloudflare supports it.
- If you use Auth at origin or IP-based restrictions, add Cloudflare’s IP ranges to allowlist.
- Check server performance: slow PHP/FPM, database, or upstream calls can hit edge timeout limits.
CloudFront
- Ensure origin hostname resolves and is reachable from AWS POPs. If origin is an ALB/NLB, verify health and security groups.
- If using S3:
- When private, use Origin Access Control (OAC) or Origin Access Identity (OAI). Public buckets may introduce security risks.
- 403s indicate missing bucket policy or wrong OAC/OAI attachment.
- Use Origin Connection Attempts/Timeout settings thoughtfully (Default: 10s timeout). Increase if origin needs more time, or optimize origin performance.
- Consider Origin Shield to reduce origin load and improve cache hit ratio.
Checks
- curl -I http://origin.example.com
- From an EC2 instance in various regions, test connectivity to origin.
- Review origin server logs for corresponding inbound requests.
4) Cache Behavior: Misses, Stale Content, and Overfetching
Symptoms:
- CDN never caches content or always returns MISS/BYPASS.
- Stale content sticks after a deploy.
- Cache works for some URLs but not others.
Cloudflare
- CF-Cache-Status values:
- HIT, MISS, EXPIRED, BYPASS, DYNAMIC.
- Many dynamic responses won’t cache by default if they set Set-Cookie or Cache-Control: private.
- Fixes:
- Use Cache Rules (or Page Rules legacy) to “Cache Everything” for static-like dynamic pages and “Bypass Cache on Cookie” for auth sessions.
- Set Edge Cache TTL where appropriate.
- Control cache with Cache-Control and ETag headers from your origin.
- Enable Brotli and GZIP compression.
- Purge cache after deployments. Prefer tag-based purge if integrated; otherwise purge by prefix or URL.
CloudFront
- X-Cache values:
- Miss from cloudfront, Hit from cloudfront, Error from cloudfront.
- CloudFront caches based on Cache Policy (headers, cookies, query strings). If you vary on too many headers, the cache will fragment.
- Fixes:
- Use managed Cache Policies for typical assets (Managed-CachingOptimized).
- Forward only necessary headers/cookies in Origin Request Policy.
- Set long TTLs for static assets; version file names with hashes.
- Configure compression; ensure Content-Type is correct to enable compression.
Invalidate precisely
- Cloudflare: Purge by URL, prefix, or tags (API).
- CloudFront: Create invalidations for changed paths; avoid global /* invalidations unless necessary.
5) Redirect Loops and Protocol Mismatches
Symptoms:
- ERR_TOO_MANY_REDIRECTS in browsers.
- HTTP to HTTPS loops between edge and origin.
Cloudflare
- Root cause often Flexible SSL. The edge requests origin over HTTP, while origin forces HTTPS—loop.
- Solution: Switch to Full (Strict) and keep redirects consistent (either at edge or origin—not both redundantly).
CloudFront
- Set Viewer Protocol Policy to Redirect HTTP to HTTPS and keep origin logic simple.
- Ensure origin doesn’t redirect HTTPS back to HTTP inadvertently (misconfigured rewrite rules).
Example Nginx redirect
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
6) CORS and Preflight Failures
Symptoms:
- Browser console: CORS policy errors; blocked by CORS header absence.
- Preflight (OPTIONS) returns 403 or missing Access-Control-Allow-* headers.
Cloudflare
- Use Transform Rules or Workers to add CORS headers for specific paths.
- Ensure edge caching doesn’t strip CORS headers inadvertently.
CloudFront
- Attach a Response Headers Policy (Managed-CORS-with-preflight) to add CORS headers.
- Ensure OPTIONS method is allowed in Behavior and cached appropriately (short TTL).
- If using Lambda@Edge or CloudFront Functions, ensure they return CORS headers consistently.
Basic CORS header example
Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Max-Age: 86400
7) Access Control: Signed URLs/Cookies and Private Content
Symptoms:
- 403 Forbidden via CDN but works from origin.
- Links that require signed URLs fail.
Cloudflare
- Validate token generation logic and clock skew between token issuer and edge.
- For Stream or R2 with tokenized access, confirm signature, path, and expiration.
CloudFront
- For private S3 or restricted origins, use signed URLs/cookies with the correct CloudFront key pair.
- If using Origin Access Control to S3, ensure bucket policy allows the distribution SourceArn and denies public access.
Sample S3 bucket policy for OAC
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCloudFrontServicePrincipalReadOnly",
"Effect": "Allow",
"Principal": { "Service": "cloudfront.amazonaws.com" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-site-bucket/*",
"Condition": {
"StringEquals": {
"AWS:SourceArn": "arn:aws:cloudfront::123456789012:distribution/EDFDVBD6EXAMPLE"
}
}
}
]
}
8) Mixed Content and HSTS Pitfalls
Symptoms:
- Some assets blocked as insecure; HSTS warnings.
- Site breaks only on HTTPS.
Fixes
- Serve all assets over HTTPS; update hardcoded http:// links.
- Use Content Security Policy (CSP) to define allowed asset domains.
- Be cautious with HSTS preload; verify all subdomains serve HTTPS before enabling preload and includeSubDomains.
9) Encoding and Compression Oddities
Symptoms:
- Garbled text or binary output; incorrect Content-Type.
- Duplicate compression (double gzip), or uncompressed large payloads.
Fixes
- Set correct Content-Type and Content-Encoding at origin.
- Enable Brotli (Cloudflare) and compression (CloudFront behavior), but avoid compressing already-compressed assets (images, video, archives).
- Ensure Vary: Accept-Encoding is set appropriately.
10) IPv6 and HTTP/3 Edge Cases
Symptoms:
- Site works on some networks only; IPv6 users fail.
- HTTP/3-specific transport issues.
Fixes
- Enable IPv6 on both Cloudflare and CloudFront.
- Test with and without HTTP/3. If issues persist, temporarily disable HTTP/3 to isolate.
- Confirm origin supports IPv6 if you use DNS AAAA records and direct origin access.
11) Security Layers and False Positives
Symptoms:
- Some users see 403/Challenge pages; API clients blocked.
- Spikes in WAF blocks after a release.
Cloudflare
- Review Security → Events; identify triggered rules.
- Add bypass rules for known safe traffic (API paths, admin IPs).
- Use Bot Management/Rate Limiting tuned to your traffic patterns.
CloudFront
- Check AWS WAF logs and sampled requests.
- Scope-down statements to exclude safe paths or IP sets.
- Attach per-behavior WAF associations if necessary.
Cloudflare: Error Codes and Targeted Fixes
- 520 Unknown Error
- Origin returned unexpected/empty response. Check origin logs, PHP/CGI crashes, or large headers.
- 521 Web Server Is Down
- Connection refused. Verify origin is up and accepting connections; allowlist Cloudflare IPs.
- 522 Connection Timed Out
- Edge cannot connect in time. Check firewall, routing, load, or slow origin.
- 523 Origin Is Unreachable
- DNS/unroutable origin. Verify origin hostname resolves and is reachable from the internet.
- 524 A Timeout Occurred
- Origin took too long to respond. Optimize backend, raise timeouts cautiously.
- 525 SSL Handshake Failed
- TLS mismatch. Use Full (Strict), fix origin cert/SNI, ensure supported ciphers.
- 526 Invalid SSL Certificate
- Origin certificate invalid or hostname mismatch. Install valid cert (Let’s Encrypt or Cloudflare Origin Cert).
- 530 (custom/unknown)
- Often indicates ban or custom error. Inspect firewall/WAF and challenge pages.
Headers to check
- CF-Ray: unique request ID; share with Cloudflare support.
- CF-Cache-Status: HIT/MISS/BYPASS.
- Server: cloudflare (confirm traffic is through edge).
Quick Cloudflare workflow
- Pause proxy (gray cloud) to confirm origin works.
- Restore proxy (orange cloud) and test.
- Fix SSL mode to Full (Strict).
- Allowlist Cloudflare IPs; confirm origin open ports.
- Adjust Cache Rules and WAF exceptions per path.
CloudFront: Configuration Pitfalls and Remedies
- Alternate Domain and Certificate
- Add domain to distribution; attach ACM cert in us-east-1 that covers the domain.
- Behaviors and Policies
- Viewer Protocol Policy: Redirect HTTP to HTTPS.
- Choose a Cache Policy that doesn’t over-vary (headers/cookies/queries).
- Use Origin Request Policy to pass only necessary values to origin.
- Attach Response Headers Policy for CORS/security headers.
- Origins
- For S3: use OAC or OAI; lock bucket to only CloudFront.
- For ALB/EC2: Check health, SGs, and Host header expectations.
- Origin Path must match your directory/subpath needs.
- Logging
- Enable standard logs to S3 and real-time logs for debugging spike issues.
- Error Pages
- Configure Custom Error Responses to serve friendlier error pages and cache certain 4xx/5xx briefly to shield origin.
Headers to check
- X-Cache: Hit from cloudfront | Miss from cloudfront | Error from cloudfront.
- X-Amz-Cf-Id: request identifier for AWS support.
- X-Amz-Cf-Pop: POP location.
Practical, Step-by-Step Scenarios
Scenario 1: Cloudflare 526 Invalid SSL Certificate After Enabling Proxy
Symptoms: Visiting https://example.com returns Cloudflare 526.
Fix:
- On your origin, install a valid certificate:
- Let’s Encrypt:
- Use certbot to issue a certificate for example.com and www.example.com.
- Or Cloudflare Origin Certificate:
- Generate in Cloudflare dashboard; install on your server; trust chain is validated by Cloudflare edge.
- Let’s Encrypt:
- In Cloudflare, set SSL/TLS → Overview to Full (Strict).
- Test with curl:
- curl -I https://example.com
- Confirm 200 and CF-Cache-Status present.
- If using HSTS, verify subdomains and preload settings don’t force HTTPS to a host lacking a valid cert.
Scenario 2: CloudFront + S3 Returns 403 Forbidden After Making Bucket Private
Symptoms: Public site now 403s through CloudFront; S3 works with presigned URLs.
Fix:
- Create/attach an Origin Access Control (OAC) to your origin in CloudFront.
- Update S3 bucket policy to allow CloudFront service principal with SourceArn (see policy example above).
- Block all public access in S3 (recommended).
- In the CloudFront behavior, ensure you’re not forwarding Authorization headers unless required.
- Invalidate cache for affected paths if policy changed recently.
- curl -I https://example.com/assets/app.css and confirm X-Cache: Hit from cloudfront.
Scenario 3: Intermittent 522 Timeouts on Cloudflare During Traffic Spikes
Symptoms: Peak traffic yields 522s; origin looks saturated.
Fix:
- Allowlist Cloudflare IP ranges on origin to avoid rate-limiting the edge.
- Enable Keep-Alive and connection reuse on your web server/reverse proxy.
- Add caching rules at Cloudflare:
- Cache Everything for static-rendered HTML if applicable.
- Bypass cache for session-authenticated requests; cache static assets with long TTL.
- Optimize origin:
- Use a performant app server, connection pooling for DB/external APIs.
- Consider Argo Smart Routing (optional) to reduce latency to origin.
- Monitor CF-Cache-Status and origin metrics; increase origin capacity if sustained.
Scenario 4: CORS Errors for API Behind CloudFront
Symptoms: Browser says “No Access-Control-Allow-Origin header present.”
Fix:
- Attach Managed-CORS-with-preflight Response Headers Policy to the API behavior.
- Ensure OPTIONS method is allowed and cached with a short TTL.
- If API requires credentials, set Access-Control-Allow-Credentials: true and do not use wildcard origin; echo the requesting origin header.
- Validate with curl:
- curl -H "Origin: https://app.example.com" -H "Access-Control-Request-Method: POST" -X OPTIONS -I https://api.example.com/login
Deep Diagnostics: Headers and Commands You’ll Use Constantly
- curl (status and headers)
- curl -I https://example.com
- curl -svo /dev/null https://example.com
- Verify CDN vs origin
- curl -H "Cache-Control: no-cache" -I https://example.com
- Compare with origin direct: curl -I https://origin.example.internal
- DNS checks
- dig example.com +short
- dig CNAME www.example.com
- Cache identity
- Cloudflare: CF-Cache-Status: HIT/MISS/BYPASS; CF-RAY: id-pop
- CloudFront: X-Cache, X-Amz-Cf-Pop, Age headers
Automation Snippets (IaC)
CloudFront with OAC and basic behaviors (Terraform-like pseudocode)
resource "aws_cloudfront_distribution" "site" {
enabled = true
aliases = ["example.com", "www.example.com"]
default_root_object = "index.html"
origins {
domain_name = "my-site-bucket.s3.amazonaws.com"
origin_id = "s3-origin"
origin_access_control_id = aws_cloudfront_origin_access_control.oac.id
}
default_cache_behavior {
target_origin_id = "s3-origin"
viewer_protocol_policy = "redirect-to-https"
cache_policy_id = data.aws_cloudfront_cache_policy.caching_optimized.id
response_headers_policy_id = data.aws_cloudfront_response_headers_policy.cors_preflight.id
}
viewer_certificate {
acm_certificate_arn = aws_acm_certificate.us_east_1.arn
ssl_support_method = "sni-only"
minimum_protocol_version = "TLSv1.2_2021"
}
}
Cloudflare: Force Full (Strict) and cache rule (conceptual via API/TF)
# SSL mode
resource "cloudflare_zone_settings_override" "ssl" {
zone_id = var.zone_id
settings {
ssl = "strict"
always_use_https = "on"
}
}
# Cache rule (Cache Everything on /blog/ with Edge TTL 1h)
resource "cloudflare_ruleset" "cache_rules" {
zone_id = var.zone_id
name = "Cache Rules"
kind = "zone"
phase = "http_request_cache_settings"
rules {
description = "Cache blog"
expression = "(http.request.uri.path matches \"^/blog/\")"
action = "set_cache_settings"
action_parameters {
cache = true
edge_ttl {
mode = "override_origin"
default = 3600
}
origin_cache_control = "respect_origin"
}
}
}
Note: Adjust for your tooling and version; Cloudflare’s Rulesets evolve rapidly.
Performance Tweaks That Avoid Configuration Pitfalls
- Cache keys
- Avoid varying on unnecessary headers or cookies. Both Cloudflare and CloudFront let you explicitly control what varies.
- Static asset strategy
- Long TTLs + filename hashing; immutable assets reduce invalidations.
- Compression and image optimization
- Enable Brotli/Gzip; consider WebP/AVIF at origin or via Cloudflare Images/Transform.
- Connection reuse
- Keep-Alive on origin; tune max connections and timeouts.
- Origin protection
- Use Cloudflare WAF or AWS WAF to block obvious bad traffic, but add scoped exceptions for API paths and health checks.
- Monitoring
- Turn on CDN logs; track cache hit ratio, error rates, and TTFB over time.
Preventive Maintenance Checklist
- DNS
- Confirm NS records and CNAME mappings; document all domains mapped to CDNs.
- Certificates
- Calendar reminders for expirations; automate renewal via ACME or origin certs.
- For CloudFront, ACM in us-east-1 for all alternate names.
- Cache Rules and Policies
- Audit cache behaviors quarterly. Ensure dynamic endpoints aren’t cached unintentionally.
- Security Rules
- Review WAF rules after app changes; adjust for new endpoints.
- Origin Health
- Load test critical paths; ensure capacity for peaks.
- Monitor upstream dependencies (DB, APIs) that impact origin latency.
- Logging and Alerts
- Enable structured logs (Logpush, CloudFront real-time). Alert on 5xx spikes and cache hit drops.
When to Bypass the CDN Temporarily
If you’re stuck, bypass the CDN to isolate origin issues:
- Cloudflare: Set DNS to DNS-only (gray cloud) for a subset of records; or create a temporary direct origin subdomain.
- CloudFront: Access origin directly via an internal host or temporary DNS record not routed through CloudFront.
Once you confirm origin health, re-enable the CDN and re-test. This isolates where configuration fixes are required.
Bringing It All Together
Troubleshooting CDN configuration errors is a process of elimination:
- Start at DNS and certificates to ensure the right edge is in front of the right hostnames with valid TLS.
- Verify origin connectivity and that firewalls trust your CDN’s egress IPs.
- Align cache behavior with your app’s needs—cache what’s safe, bypass what’s not, and avoid cache fragmentation.
- Add the right headers for CORS, compression, and security without overcomplicating behaviors.
- Use logs and headers as your compass: CF-Cache-Status, X-Cache, CF-Ray, and X-Amz-Cf-Id will tell you where the request went and what happened.
By adopting a structured approach and the practical fixes in this guide, you’ll resolve Cloudflare and CloudFront issues faster, build resilient configurations, and deliver consistently better performance to your users.