1
讓我用一個例子解釋:什麼時候應該在vcl_recv和vcl_fetch下添加相同的策略?
文件: /etc/varnish/default.vcl
# [...]
sub vcl_recv {
# [...]
if (req.request != "GET" && req.request != "HEAD") {
return (pass);
}
if (req.http.Authorization || req.http.Authenticate) {
return (pass);
}
if (req.url ~ "wp-(login|admin|comments-post.php|cron.php)") {
return (pass);
}
# [...]
return (lookup);
}
sub vcl_fetch {
# [...]
if (req.request != "GET" && req.request != "HEAD") {
return (hit_for_pass);
}
if (req.http.Authorization || req.http.Authenticate) {
return (hit_for_pass);
}
if (req.url ~ "wp-(login|admin|comments-post.php|cron.php)") {
return (hit_for_pass);
}
# [...]
return (deliver);
}
正如你所看到的,因爲這不應該被緩存的內容,我有同樣的政策分別爲vcl_recv
和vcl_fetch
,但分別爲return (pass);
和return (hit_for_pass);
。
在某些情況下,應該完成這項工作(when it is useful),以及其他絕對不必要的情況。他們是什麼? (如Cookies?如果是這樣,怎麼辦?)