Nginx缓存:如何忽略“无缓存”,却像“公开”一样尊重“最大年龄”?

问题描述 投票:0回答:1

我想发送给浏览器Cache-Control: no-cache,max-age=120;,因此它们必须重新验证才能使用缓存的副本,但这实际上使Nginx不缓存任何内容,或者至少不缓存MISS

而且我不能使用proxy_ignore_headers “Cache-Control”;,因为我必须遵守max-age,并且max-age由上游服务器控制,每种类型的页面都有不同的页面,并且可能随时间而变化,因此必须由主服务器。

如何配置才能获得此?

PD:或者一种使Nginx接受某些自定义X-Cache-Control标头,并使用单独的标头来控制代理和浏览器缓存的方法。

PD2:我做到了,显然可行,但是我希望采用一种更“正式”的方式:

proxy_hide_header Cache-Control;
proxy_hide_header maxage;
add_header Cache-Control "no-cache,max-age=$upstream_http_maxage";
nginx caching proxy reverse-proxy cache-control
1个回答
0
投票

我认为您应该使用proxy_hide_header而不是proxy_ignore_headers

© www.soinside.com 2019 - 2024. All rights reserved.