Plainnotes

proxy_cache hit rate depends on the key

2025-05-14 · 2 min readDeploy

Static assets behind nginx cache at a 30% hit rate, with MISS everywhere. Usually the key.

The default is $scheme$proxy_host$request_uri, so different Host headers and every query string become separate entries. Cache-busting parameters like ?v=123 or tracking parameters shred the cache.

Choose per case:

proxy_cache_key "$scheme$host$uri";               # ignore query string
proxy_cache_key "$scheme$host$uri$is_args$args";   # keep it

Also decide whether upstream Cache-Control or proxy_cache_valid wins; by default an upstream no-cache overrides your validity settings unless ignored.

Add $upstream_cache_status to a response header while debugging — HIT, MISS or BYPASS at a glance.