【问题标题】:Symfony2, Varnish and ESI lead to strange behaviorSymfony2、Varnish 和 ESI 导致奇怪的行为
【发布时间】: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 函数):&lt;esi:include src="/esiinner" /&gt;
  • /esiinner s-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 的替代品。

标签: symfony varnish esi


【解决方案1】:

如果您有软件网关缓存/反向代理(如 Varnish),则无需启用 AppCache(这是用 PHP 编写的 Symfony2 反向代理)。

启用AppCache 可能会导致不一致的行为,因为您将拥有 2 个反向代理。

【讨论】:

  • 让我烦恼的是Symfony documentation about caches 声明:[...] 好消息是,从一个代理服务器切换到另一个代理服务器既简单又透明,因为无需修改代码在您的应用程序中需要。 [...]。但是在app.php 中删除AppCache 是一种修改。也许这是吹毛求疵,但我想确定AppCache 真的是只是 Symfony 的反向代理,仅此而已。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-27
  • 1970-01-01
  • 2017-07-21
  • 1970-01-01
  • 1970-01-01
  • 2011-08-23
相关资源
最近更新 更多