我想仅为登录用户启用esi。注销用户应该通过缓存整页提供。
我在下面写了vcl。问题在于,一旦缓存登录页面或登出页面,它就会向所有人显示相同内容。
vcl_recv {
if (req.http.Cookie ~ "loggedIn") {
if (req.url ~ "^/esi")
{
return (pass);
}
if (req.url ~ "page"){
return (lookup);
}
return (pipe);
}
return (lookup);
}
sub vcl_pipe {
set bereq.http.connection = "close";
}
sub vcl_fetch {
if (req.url ~ "page"){
set beresp.do_esi = true;
set beresp.ttl = 1d;
return (deliver);
}
set beresp.ttl = 1d;
return (deliver);
}
一个解决方案似乎是在url和LoggedIn cookie的组合上使用vcl_hash,它有两个值0或1.请建议。
答案 0 :(得分:0)
我使用下面的cookie值给出答案
sub identify_cookie{
#Call cookie based detection method in vcl_recv
if (req.http.cookie ~ "loggedIn=") {
set req.http.loggedIn = regsub(req.http.cookie, "(.*?)(loggedIn=)([^;]*)(.*)$", "\3");
}
}
sub vcl_recv {
call identify_cookie; #Used to get identify cookie and get its value
if(req.http.loggedIn && req.url ~ "^/esi"){
#used to get value using cookie value
return (pass);
}
if (req.url !~ "wp-(login|admin)" && req.http.Cookie !~ "loggedIn"){
#remove all the request cookie(s) except loggedIn and check for wordpress admin
unset req.http.Cookie;
}
}
sub vcl_fetch {
if(req.http.loggedIn && req.url ~ "^/esi") {
return (hit_for_pass);
}
if (req.url !~ "wp-(login|admin)" && beresp.http.set-Cookie !~ "loggedIn"){
#remove all the response cookie(s) except loggedIn and check for wordpress admin
unset beresp.http.Set-Cookie;
}
}