我使用光油3.0.3并通过在静态资源的HTTP标头中设置最大年龄来利用浏览器缓存。我尝试添加下列配置。default.vcl:光油3 - 如何在http标题中设置最大年龄
sub vcl_fetch {
if (beresp.cacheable) {
/* Remove Expires from backend, it's not long enough */
unset beresp.http.expires;
/* Set the clients TTL on this object */
set beresp.http.cache-control = "max-age=900";
/* Set how long Varnish will keep it */
set beresp.ttl = 1w;
/* marker for vcl_deliver to reset Age: */
set beresp.http.magicmarker = "1";
}
}
sub vcl_deliver {
if (resp.http.magicmarker) {
/* Remove the magic marker */
unset resp.http.magicmarker;
/* By definition we have a fresh object */
set resp.http.age = "0";
}
}
这是从https://www.varnish-cache.org/trac/wiki/VCLExampleLongerCaching复制。也许我只是犯了一个错字。重新启动Varnish后,它不再起作用。
我有两个问题。这是用于清漆3的正确方法吗?如果是这样,我做错了什么?其次,在重启之前有没有办法测试Varnish配置文件? “Apache/sbin/service httpd configtest”的一些方法。在上线之前就会发现错误。谢谢。