我使用光油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」的一些方法。在上線之前就會發現錯誤。謝謝。