在交货时更换标题
以下 VCL sn-p 将在发送到客户端之前从 Cache-Control 标头中去除 s-maxage 属性。
sub vcl_deliver {
set resp.http.cache-control = regsub(resp.http.cache-control,
"(,\s*s-maxage=[0-9]+\s*$)|(\s*s-maxage=[0-9]+\s*,)","");
}
在存储时替换标题
还可以在将Cache-Control 标头中的此属性存储到缓存对象之前将其剥离。在这种情况下,您将在vcl_backend_response 中使用beresp.http.cache-control 变量。
sub vcl_backend_response {
set beresp.http.cache-control = regsub(beresp.http.cache-control,
"(,\s*s-maxage=[0-9]+\s*$)|(\s*s-maxage=[0-9]+\s*,)","");
}
使用 vmod_headerplus
如果您使用的是Varnish Enterprise,您可以使用vmod_headerplus 模块轻松删除标题属性:
vcl 4.1;
import headerplus;
sub vcl_deliver {
headerplus.init(resp);
headerplus.attr_delete("Cache-Control","s-maxage",",");
headerplus.write();
}
vcl 4.1;
import headerplus;
sub vcl_backend_response {
headerplus.init(beresp);
headerplus.attr_delete("Cache-Control","s-maxage",",");
headerplus.write();
}
虽然 Varnish Enterprise 是 Varnish Cache 的商业版本,但如果您在 AWS、Azure 或 GCP 上使用它,您仍然可以使用它而无需预先支付许可费用。 p>