问题原文
原帖链接 · dlrust · CC BY-SA 4.0
I have caching enabled on an NGINX proxy.
As I understand it, as long as I'm not ignoring the Cache-Control header in my proxy configuration (proxy_ignore_headers), the cache time before expiration can be set from the origin server using Cache-Control = max-age=XXXX.
But what would be the default cache time it would keep and use for something like Cache-Control: public? Is there a way to set a default maximum cache time for these resources?
社区高分解答
原帖链接 · maxschlepzig · CC BY-SA 4.0
That is right, by default, with just proxy_cache configured, nginx only caches responses that have max-age set in the Cache-Control header.
Without any Cache-Control header or just Cache-Control: public nginx doesn't cache the response (i.e. you get each time X-Cache-Status: MISS when you also configure add_header X-Cache-Status $upstream_cache_status;).
You can configure a default caching time for responses without a Cache-Control header or ones without a max-age field in a Cache-Control header:
# for 200, 301, 302 responses
proxy_cache_valid 10m;
# for all other responses
proxy_cache_valid any 1m;
That means a Cache-Control header has precedence over a proxy_cache_valid setting and there are no defaults for proxy_cache_valid.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
