由于某些rewrite 后的html页面,http头信息里带有no-cache头,常规配置无法缓存,要修改varnish配置文件,去掉http里no-cache头,添加如下内容:
sub vcl_fetch {
if (req.url ~ "html$") {
set beresp.ttl = 10m;
set beresp.do_gzip = true;
unset beresp.http.Cache-Control;
unset beresp.http.Pragma;
set beresp.http.Cache-Control = "max-age=600";
unset beresp.http.Expires;
}
}
备注:如果rewrite后的html页面带cookie,还得在sub vcl_recv { } 配置里添加如下内容
sub vcl_recv {
if (req.request == "GET" && req.url ~ "\.(js|css|html|jpg|png|gif|swf|jpeg|ico|mp3)$") {
unset req.http.cookie;
}
}
以上配置文件,合适版本 varnish 3.0.x
sub vcl_fetch {
if (req.url ~ "html$") {
set beresp.ttl = 10m;
set beresp.do_gzip = true;
unset beresp.http.Cache-Control;
unset beresp.http.Pragma;
set beresp.http.Cache-Control = "max-age=600";
unset beresp.http.Expires;
}
}
备注:如果rewrite后的html页面带cookie,还得在sub vcl_recv { } 配置里添加如下内容
sub vcl_recv {
if (req.request == "GET" && req.url ~ "\.(js|css|html|jpg|png|gif|swf|jpeg|ico|mp3)$") {
unset req.http.cookie;
}
}
以上配置文件,合适版本 varnish 3.0.x
转载于:https://blog.51cto.com/cqfish/684499