[英]Varnish 4, cache page with cookies
I want to cache every page (even with cookies), backend in php is not prepared for this, so it's sending multiple Set-Cookie headers. 我想缓存每个页面(甚至包含cookie),php的后端对此没有准备,因此它发送了多个Set-Cookie标头。 When I remove all session_start and setcookie funcitons, the page HITs, but when I set my vcl to varnish do it automatically for me, page allways MISSes.
当我删除所有session_start和setcookie功能时,页面会命中(HIT),但是当我将vcl设置为清漆时,页面会自动为我执行,这时页面总是会出错。
Here is my default.vcl : 这是我的default.vcl :
vcl 4.0;
backend default {
.host = "myhost.app";
.port = "80";
}
sub vcl_recv {
unset req.http.cookie;
}
sub vcl_backend_response {
unset beresp.http.set-cookie;
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
It seems you are going into muddy waters, but try forcing a ttl: 看来您要进入泥泞的水域,但请尝试强制执行ttl:
sub vcl_backend_response {
set beresp.ttl = 120 s;
unset beresp.http.set-cookie;
}
Check that you are not breaking things by caching ignoring cookies and ttls. 通过缓存忽略cookie和ttl来检查您是否没有破坏事物。
I was also facing cache MISS every time and updated sub vcl_backend_response{..}
as mentioned by Jorge Nerín. sub vcl_backend_response{..}
所说,我每次都还要面对高速缓存MISS,并更新了sub vcl_backend_response{..}
。 Now It was showing cache HIT, but login was not happening. 现在,它正在显示高速缓存命中率,但未发生登录。 It was obvious because of
unset beresp.http.set-cookie;
由于未
unset beresp.http.set-cookie;
因此很明显unset beresp.http.set-cookie;
. 。 So I get idea from Manipulating request headers in VCL to unset cookie based on URL.
因此,我从在VCL中处理请求标头以根据URL取消设置cookie 中获得了灵感。 I applied same in
vcl_backend_response
. 我在
vcl_backend_response
应用了相同的vcl_backend_response
。 In my app login URL contains auth
. 在我的应用中,登录URL包含
auth
。 So I updated to unset beresp.http.set-cookie;
所以我更新为未
unset beresp.http.set-cookie;
every where except when URL contain auth
. 除URL包含
auth
以外的所有地方。 Now login is happening and also cache HIT. 现在登录正在进行,并且还缓存HIT。 Hope this helps community
希望这对社区有所帮助
sub vcl_backend_response {
set beresp.ttl = 120 s;
if ((bereq.url ~ "auth")){
}
else{
unset beresp.http.set-cookie;
}
#rest of code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.