我使用的是Varnish 3.0.3,并通过在静态资源的HTTP标头中设置最大寿命来利用浏览器缓存。我尝试将以下配置添加到default.vcl:
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时,它不再起作用。
我有两个问题。对于Varnish 3,这是正确的方法吗?如果是这样,我做错了什么?其次,有没有办法在重启之前测试Varnish配置文件?类似Apache的"/sbin/service httpd configtest“。它可以在上线前捕获错误。谢谢。
发布于 2012-10-13 06:46:49
是的,一般来说,这是覆盖后端TTL的方式。删除控制,设置beresp.http.cache- beresp.http.expires,设置beresp.ttl。beresp.cacheable是2.01-ism。3.0中的相同测试是检查beresp.ttl > 0。
一个小技巧是将你的魔术标记存储在req.http上,这样你就不必在将对象传递给客户端之前清理它。
关于测试配置文件,您可以直接调用VCL编译器,例如"varnishd -C -f /etc/varnish/default.vcl“。如果你的VCL有问题,你会得到错误信息,如果VCL是有效的,你会得到几页生成的C代码。
https://stackoverflow.com/questions/12864245
复制相似问题