CDN tiers and invalidation
Follow the response through two cache tiers
A CDN edge near a reader may cache the response from your Nginx origin proxy, which may itself cache an application response. A browser can cache a third copy. Each tier has its own entries, eligibility and expiry. HTTP Age and cache-specific logs help diagnose the path, but one layer’s HIT says nothing conclusive about another layer. Keep the origin private to the approved delivery path where architecture permits; use TLS verification, restricted reachability and a trusted forwarding policy.
Browser -> CDN edge -> Nginx origin cache -> catalog appEdge HIT: no Nginx request requiredEdge MISS + Nginx HIT: no app request requiredBoth MISS: app generates responseDeploy assets without depending on purge
Versioned names change the URL when the bytes change. Upload new immutable public assets first, verify them, then release HTML referencing the new names. Keep old assets available during the documented rollback window and until old HTML is no longer served. For mutable HTML, use an explicit shorter freshness or revalidation policy. The hash strings in the next example are schematic version labels, not computed digests.
1. Publish /assets/site-v2.css2. Verify status, content and expected version3. Publish HTML referencing site-v2.css4. Keep site-v1.css for old HTML and rollback5. Retire only after the retention windowInvalidation and storage lifecycle
The cache manager removes entries to control cache storage; the loader reconstructs metadata for previously stored files after startup. Neither is a global invalidation service. Official proxy_cache_purge is commercial functionality; other modules have separate contracts. A local purge cannot remove copies from browsers or CDN nodes. An authorized invalidation workflow must scope keys and tiers, verify propagation and avoid making a private origin accessible. Signed URLs are time-limited authorization tokens, not merely a cache-key trick: preserve the authorization contract at each tier, and do not cache private downloads unless the security design has been verified.
Optional range caching: slice module
Large immutable files may benefit from caching chunks instead of fetching the whole object. The optional slice module, introduced in 1.9.8, requires build support. With caching, include the slice range in the key, request that range upstream and allow caching 206. The origin must honor Range and keep the representation stable. Do not use this with background cache update: the module documentation identifies a known incompatibility. Small slice sizes increase file and memory overhead.
location /downloads/ { slice 512k; proxy_cache public_downloads; proxy_cache_key "$scheme|$host|$request_uri|$slice_range"; proxy_set_header Range $slice_range; proxy_cache_valid 200 206 10m; proxy_cache_background_update off; proxy_pass http://127.0.0.1:8091;}Prerequisites for this fragment
Define the zone in http, accept only known hosts and use the exclusions from Chapter 25 for cookies and authorization. The origin must be dedicated to public immutable downloads; the V27 lab does not implement byte ranges and does not execute this example. For a production range test, verify Content-Range, bytes at chunk boundaries, cache-key separation and the complete object digest. Never treat a partial-body 206 as a full 200.
proxy_cache_path download-cache keys_zone=public_downloads:2m max_size=32m inactive=10m use_temp_path=off;Practice
Draw the three cache tiers and write a rollout/rollback checklist. Explain why a local purge does not guarantee global deletion. Next: compression and static delivery optimization.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
CDN tiers and invalidation
Plan safe multi-tier delivery, versioned asset rollouts and optional range caching while distinguishing edition-specific purge support.
What does an edge HIT prove about the app?
Which deployment order avoids missing new assets?
Is official proxy_cache_purge available in standard open-source Nginx?
What must a slice cache key include?
Which combination has a documented slice-module issue?