我在成功使用带有 Varnish 3.0 的 ESI 和 repoze.bfg 项目时遇到问题。我有一个 ESI 片段,它通过 ESI 标签显示登录用户的通知。但是,varnish 会缓存包含的 ESI 片段,因此对片段所做的更改,无论是手动的,还是会话的结果都不会反映在包含(和缓存的)网页中。
使用的 ESI 标签:
VCL 配置:
sub vcl_recv {
if (req.url ~ "[A-Za-z0-9_-]*.esi$") {
return (pass);
}
if (req.http.cookie) {
set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?", "");
if (req.http.cookie ~ "^ *$") {
remove req.http.cookie;
}
}
remove req.http.cookie;
remove req.http.etag;
}
sub vcl_fetch {
remove beresp.http.Set-Cookie;
remove beresp.http.ETag;
#do esi processing
set beresp.do_esi = true;
if (bereq.url ~ "[A-Za-z0-9_-]*.esi$") {
set beresp.ttl = 0s;
} else {
set beresp.ttl = 24h;
}
}
我的假设是:
1) Varnish 每次从其缓存存储中获取时都会向“path/to/fragment.esi”和重新组装缓存网页发出请求,特别是因为对于每个 .esi 片段, beresp.ttl 都设置为 0 2) Varnish不会将 ESI 片段与网页一起存储在其缓存存储中**