Origin Server Configuration for CDN: Best Practices
The origin server is the authoritative source of content that a CDN caches and distributes across its edge servers. Proper origin configuration is the foundation of effective CDN performance: misconfigured headers can prevent caching entirely, missing health checks can cause downtime during origin failures, and exposed origin IPs can bypass all CDN security protections. This guide covers the essential configuration practices that separate a well-tuned CDN deployment from a broken one.
How Does Origin Pull Configuration Work?
In a pull-based CDN model, edge servers fetch content from your origin on demand. When a user requests a resource that is not in the edge cache (a cache miss), the edge server sends an HTTP request to your origin, retrieves the response, caches it according to the headers, and serves it to the user. Subsequent requests for the same resource are served directly from cache without contacting the origin.
Configuring pull correctly requires specifying your origin address in the CDN control panel (IP address or hostname), the protocol (HTTP or HTTPS), the port, and any custom Host header the origin expects. A common mistake is pointing the CDN to a hostname that resolves back to the CDN itself, creating an infinite loop. Always use either the origin IP address directly or a dedicated origin hostname (such as origin.example.com) that resolves to your actual server.
For initial CDN setup, test origin connectivity by making direct requests to your origin server with the expected Host header and verifying that responses include correct Cache-Control headers before enabling the CDN.
What Cache-Control Headers Should the Origin Send?
Cache-Control headers from the origin are the primary mechanism for telling the CDN what to cache and for how long. Getting these right is the single most impactful configuration decision you will make. Here is a recommended header strategy by content type:
| Metric | Edge Processing | Origin Processing | Improvement |
|---|---|---|---|
| Latency (p50) | 8–15 ms | 120–300 ms | 15–20x faster |
| Cache Hit Ratio | 85–95% | N/A | Reduces origin load |
| TLS Handshake | 1–5 ms (nearby PoP) | 50–150 ms | 10–30x faster |
| Bandwidth Cost | $0.01–0.04/GB | $0.05–0.12/GB | 3–5x cheaper |
| Availability | 99.99% (multi-PoP) | 99.9% (single DC) | 10x fewer outages |
| Content Type | Recommended Cache-Control | TTL | Rationale |
|---|---|---|---|
| Hashed static assets (app.a1b2c3.js) | public, max-age=31536000, immutable | 1 year | Content-addressable; filename changes on update |
| Unhashed static assets (logo.png) | public, max-age=86400, s-maxage=604800 | 7 days CDN, 1 day browser | May change; CDN holds longer than browser |
| HTML pages | public, max-age=0, s-maxage=3600, stale-while-revalidate=86400 | 1 hour CDN, revalidate always in browser | Frequently updated; stale-while-revalidate for resilience |
| API responses (public) | public, s-maxage=60, stale-while-revalidate=300 | 1 minute CDN | Short TTL with stale fallback for availability |
| User-specific content | private, no-store | None | Must never be cached by shared CDN cache |
| Fonts | public, max-age=31536000, immutable | 1 year | Rarely change; critical for rendering performance |
The s-maxage directive is especially important because it overrides max-age for shared caches (CDNs) without affecting browser cache behavior. This lets you cache aggressively at the edge while keeping browser caches conservative. For a deeper exploration of header mechanics, see the cache-control headers deep dive.
How Should I Set Up an Origin Shield?
An origin shield is an intermediate caching tier that consolidates cache misses from all edge PoPs before they reach your origin. Without a shield, if your CDN has 300 edge PoPs and a popular resource expires simultaneously, your origin could receive 300 concurrent requests for the same object. With a shield, only one request reaches your origin.
Configuration steps for major providers:
- Choose the shield location — Select a PoP closest to your origin server. If your origin is in AWS us-east-1, choose the CDN shield in the same region to minimize fetch latency.
- Enable the shield in your CDN settings — Most providers offer this as a toggle with a location selector. Cloudflare calls it Tiered Caching. CloudFront calls it Origin Shield.
- Verify the cache hierarchy — Requests should flow: Edge PoP → Shield PoP → Origin. Check response headers (X-Cache, Via) to confirm the hierarchy is active.
- Monitor shield hit ratio — A well-functioning shield should have a 95-99% cache hit ratio, meaning only 1-5% of unique content requests reach your origin.
Origin shields are most beneficial when your origin is in a single location and your audience is global. They reduce origin bandwidth by 80-95% compared to unshielded configurations, directly lowering both load and egress costs. The cache hierarchy article provides additional depth on multi-tier caching architectures.
How Do I Configure Origin Failover?
Origin failover ensures your site remains available even when your primary origin experiences downtime. A properly configured failover setup requires multiple origin servers and automated switching logic.
Active-Passive Failover
The CDN sends all requests to the primary origin. If health checks detect the primary is down (consecutive 5xx responses or timeouts), the CDN switches to the secondary origin. When the primary recovers, traffic switches back automatically.
Active-Active Load Balancing
The CDN distributes origin requests across multiple servers using weighted round-robin or least-connections algorithms. If one origin fails health checks, its weight drops to zero, and traffic redistributes across healthy servers. This approach provides both redundancy and higher aggregate capacity.
Health Check Configuration
Effective health checks go beyond simple ping tests:
- HTTP check path — Use a dedicated health endpoint (e.g., /health) that verifies database connectivity, disk space, and application readiness rather than just returning 200 OK
- Check interval — Every 10-30 seconds, balancing between detection speed and origin load
- Failure threshold — 3 consecutive failures before marking the origin unhealthy (avoids false positives from network blips)
- Recovery threshold — 2 consecutive successes before marking the origin healthy again (prevents flapping)
- Timeout — 5-10 seconds per check; an origin that takes longer is effectively down for performance purposes
Should I Compress Content at the Origin or Let the CDN Handle It?
The short answer: let the CDN handle compression at the edge in most cases. Here is why, and when to make exceptions.
CDN-Side Compression (Recommended)
Modern CDNs compress content on the fly using Brotli (preferred for 15-20% smaller output than gzip) and gzip as a fallback. They detect the client Accept-Encoding header and serve the optimal format. The CDN caches both compressed and uncompressed variants, so the compression cost is paid once per unique object per edge PoP. This approach is simpler to manage and ensures the best compression algorithm is used for each client.
Origin-Side Compression (Special Cases)
Pre-compressing at the origin makes sense when: your CDN does not support Brotli, you need maximum compression ratios using offline Brotli level 11 (which is too CPU-intensive for real-time edge compression), or you are serving very large files where on-the-fly compression would consume significant edge CPU. If compressing at origin, always set the Content-Encoding header correctly and include Vary: Accept-Encoding to prevent cache poisoning.
How Do I Restrict Origin Access to CDN IP Addresses?
If your origin IP address is exposed, attackers can bypass the CDN and target your server directly, negating all CDN security benefits including DDoS protection and WAF filtering. Origin access restriction involves multiple layers:
IP Allow Listing
Configure your firewall (iptables, AWS Security Groups, cloud firewall) to accept HTTP/HTTPS traffic only from your CDN provider IP ranges. Major providers publish these ranges:
- Cloudflare — Published at cloudflare.com/ips, approximately 30 IPv4 and 10 IPv6 ranges
- AWS CloudFront — Published in their ip-ranges.json (filter by service CLOUDFRONT), approximately 130 ranges
- Fastly — Published at api.fastly.com/public-ip-list
Automate updates with a daily cron job that fetches the latest ranges and reloads your firewall rules, since providers add new IPs as their network expands.
Origin Authentication Headers
Add a shared secret header that the CDN sends with every origin request. Configure your origin to reject any request missing this header. This provides a second verification layer beyond IP filtering, protecting against scenarios where an attacker routes traffic through the CDN provider network.
Mutual TLS (mTLS)
For maximum security, configure mutual TLS between the CDN and your origin. The CDN presents a client certificate when connecting, and your origin validates it against a trusted CA. This cryptographically verifies that the connection originates from your CDN provider.
What Connection Settings Optimize Origin Performance?
The connection between CDN and origin can become a bottleneck if not properly tuned:
- Keep-alive connections — Enable HTTP keep-alive with a timeout of 60-120 seconds. The CDN reuses connections across multiple requests, eliminating TCP+TLS handshake overhead. A single persistent connection can serve hundreds of requests before being recycled.
- Connection limits — Set a maximum number of concurrent connections from the CDN to your origin (typically 50-200 per edge PoP). This prevents thundering herd scenarios during cache purges or traffic spikes from overwhelming your origin.
- Timeout tuning — Set connect timeout to 5 seconds, read timeout to 30 seconds, and enable retry logic with 1-2 retries on 502/503/504 responses. This balances responsiveness with resilience.
- HTTP/2 to origin — If your origin supports HTTP/2, enable it in the CDN configuration. HTTP/2 multiplexes multiple requests over a single TCP connection, further reducing connection overhead and improving throughput for pages with many uncached resources.
Proper origin configuration is not a one-time task. As your traffic patterns evolve and your content strategy changes, revisit cache-control policies, health check thresholds, and connection settings. Monitor your cache hit ratio, origin response times, and error rates to identify configuration drift before it impacts user experience. A well-configured origin is the silent backbone of every successful CDN deployment within the broader CDN architecture.