【发布时间】:2012-01-18 08:50:01
【问题描述】:
我有以下配置:
varnish (80) <-> nginx (8080) <-> php-fpm (9000)
(使用 Apache 和 mod_php 的行为相同) 我的清漆配置:
backend default {
.host = "127.0.0.1";
.port = "8080";
.connect_timeout = 600s;
.first_byte_timeout = 600s;
.between_bytes_timeout = 600s;
}
sub vcl_recv {
set req.http.Surrogate-Capability = "abc=ESI/1.0";
}
sub vcl_fetch {
if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
unset beresp.http.Surrogate-Control;
set beresp.do_esi = true;
}
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Varnish-Cache = "HIT Varnish (" +obj.hits+ ")";
} else {
set resp.http.X-Varnish-Cache = "MISS";
}
}
ESI 在app/config/config.yml 中打开。我在 symfony 中配置了以下路由:
-
/esiouter具有 s-maxage 60 并具有/esiinner的 esi-include(使用带有{'standalone': true}的“普通”esi-tag 或 twig-render 函数):<esi:include src="/esiinner" /> -
/esiinners-maxage 10(由 esi-include 获取)
现在,当我在 web/app.php 中启用 AppCache 时,symfony 会评估 ESI 标记,因此 varnish 无法获取它们,并且我们有一个 Content-Length 标头并且内容没有被分块。如果我禁用 AppCache,varnish 会评估 ESI 标记并将内容分块发送,并且没有 Content-Length 标头。
为什么 Varnish 发送的是分块响应,而不是缓冲 esi 块并作为一个整体发送页面? 如果我在带有 ESI 的 Symfony 应用程序前面使用 Varnish,我是否必须使用 Symfonys AppCache?
【问题讨论】:
-
我希望今天晚些时候有时间调查这个问题,如果你还没有自己解决?我至少可以告诉你,你不应该使用 AppCache,因为它基本上是 Varnish 的替代品。