我使用光油3,網站位於wordpress上。 問題是,當我刪除所有cookie和set-cookie標題時,清漆緩存很好。 但我需要使清漆緩存頁面取決於Cookie。 (我的網站內容取決於地理位置,所以當用戶登錄時,我第一次加餅乾「detected_country」) 首先我刪除所有設置,餅乾頭:啓用cookies後,光油不會緩存
# Drop any cookies Wordpress tries to send back to the client.
sub vcl_fetch {
if (!(req.url ~ "wp-(login|admin)")) {
unset beresp.http.set-cookie;
}
}
然後: 默認清漆做不緩存具有Cookie的請求。這是通過默認的vcl_fetch邏輯完成的。所以我改變了默認vcl_fetch和註釋掉cookie的禁令(見/*|| req.http.Cookie*/
):
sub vcl_recv {
if (req.restarts == 0) {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.Authorization /*|| req.http.Cookie*/) {
/* Not cacheable by default */
return (pass);
}
return (lookup);
}
之後,我預計清漆將緩存頁面,餅乾,但它不是:-( 但應該緩存中沒有?它
如果我刪除所有cookie它緩存OK!
sub vcl_recv {
if (!(req.url ~ "wp-(login|admin)")) {
remove req.http.Cookie;
}
}
請幫我花了很多時間來找出爲什麼它不緩存