4

I have the following config:

varnish (80) <-> nginx (8080) <-> php-fpm (9000)

(Same behavior using Apache with mod_php) My Varnish config:

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 is turned on in the app/config/config.yml. I configured the following routes in symfony:

  • /esiouter with s-maxage 60 and having an esi-include for /esiinner (using "plain" esi-tag or twig-render function with {'standalone': true}): <esi:include src="/esiinner" />
  • /esiinner with s-maxage 10 (fetched by esi-include)

Now when I enable the AppCache in web/app.php symfony evaluates the ESI tags so varnish doesn't get them and we have a Content-Length header and the content is not chunked. If I disable the AppCache, varnish evaluates the ESI tags and sends the content chunked and there is no Content-Length header.

Why is Varnish sending a chunked response and is not buffering the esi-blocks and sending the page as a whole? If I am using Varnish infront of my Symfony-Application with ESI, do I have to use Symfonys AppCache?

j0k
  • 22,600
  • 28
  • 79
  • 90
prehfeldt
  • 2,184
  • 2
  • 28
  • 48
  • 1
    I'll hopefully have time to investigate this later today, if you haven't solved it by yourself? I can at least tell you that you shouldn't use the AppCache, since this basically is a replacement for Varnish. – Manne W Dec 20 '11 at 06:37

1 Answers1

3

If you have a software Gateway cache / Reverse proxy (like Varnish) you don't need to enable AppCache (which is the Symfony2 Reverse proxy written in PHP).

Letting AppCache enabled can leads to unconsistent behaviour because you would have 2 Reverse proxies.

sf_tristanb
  • 8,725
  • 17
  • 74
  • 118
  • The thing that bugs me is that the [Symfony documentation about caches](http://symfony.com/doc/2.3/book/http_cache.html#symfony-reverse-proxy) states: [...] _The good news is that the switch from one proxy server to another is easy and transparent as no code modification is needed in your application._ [...]. But removing `AppCache` in `app.php` _is_ a modification. Maybe this is nitpicking but I want to be sure that `AppCache` really is _just_ the reverse proxy of Symfony and nothing more. – flu Nov 12 '14 at 13:51