Symfony2, Varnish and ESI lead to weird behavior

I have the following configuration:

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

(Same behavior using Apache with mod_php) My varnish configuration:

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

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

Now, when I enable AppCache in web/app.php , symfony evaluates the ESI tags, so varnishes do not receive them, and we have a Content-Length header and the content is not partitioned. If I disable AppCache, the varnish will evaluate the ESI tags and send the content, not the Content-Length header.

Why is Varnish sending a chunked response and not buffering esi blocks and sending the whole page? If I use Varnish infront of my Symfony application with ESI, do I need to use Symfonys AppCache?

+4
source share
1 answer

If you have Gateway cache / Reverse proxy software (e.g. Varnish), you do not need to enable AppCache (which is a Symfony2 Reverse proxy server written in PHP).

Enabling AppCache enabled may result in incompatible behavior because you will have 2 reverse proxies.

+3
source

Source: https://habr.com/ru/post/1385869/


All Articles