Can't get a simple proxy to cache anything

Phil Endecott nginx_list at
Sun Jan 24 12:56:35 UTC 2021

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?

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

proxy_cache_convert_head off;
proxy_cache_key "$request_method$scheme$host$request_uri";

Do I need "$is_args$args" ?

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

Many thanks,


More information about the nginx mailing list