【发布时间】:2012-10-03 13:47:37
【问题描述】:
我正在使用 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”类似。在上线之前发现错误。谢谢。
【问题讨论】:
标签: varnish varnish-vcl