Can't get a simple proxy to cache anything

Maxim Dounin mdounin at
Mon Jan 25 16:02:42 UTC 2021


On Sun, Jan 24, 2021 at 12:56:35PM +0000, Phil Endecott wrote:

> Maxim Dounin wrote:
> > You haven't configured any proxy_cache_valid directives (see 
> > for details), and the 
> > response doesn't have any cache validity headers, such as 
> > "Expires" or "Cache-Control: max-age=...".
> Thanks Maxim! It now seems to work.
> I guess I was expecting the proxy_cache_path inactive=... time
> to determine how long things were cached for. I think I have a
> better understanding now. Let me check if I have this right:
> The upstream server doesn't specify any Cache-Control or Expires
> headers. It does supply an ETag and Last-Modified. I'd like to
> cache these files for a long time (say 18 months), but revalidate
> using the ETag (say after 5 minutes). So I have:
> proxy_cache_path ... inactive=18M;
> proxy_cache_revalidate on;
> proxy_cache_valid 200 5m;  # Beware M = Month, m = minute.
> Is that right?

The "inactive=" parameter controls how long cache items are stored 
if they aren't accessed at all.  It is basically a way to control 
the total size of your cache.  Usually 18 months is way too long 
for this time.

> I have some other questions:
> 1. What proxy_cache_key should I be using? I am unsure of the difference
> between e.g. host and proxy_host, and uri and request_uri. I currently
> have
> proxy_cache_convert_head off;
> proxy_cache_key "$request_method$scheme$host$request_uri";

What cache key to use depends on your particular use case.  The 
one you are using is good enough as long as you use simple 

> Do I need "$is_args$args" ?

No, request arguments are already included in the $request_uri 
variable (see$request_uri).

> 2. Is there any way to indicate the cache status in the access log? I.e.
> hit/miss/revalidated/uncachable etc.

The cache status is available in the $upstream_cache_status 
variable ($upstream_cache_status).  If you want 
it in the logs, you can do so by configuring appropriate 
log_format (see

Maxim Dounin

More information about the nginx mailing list