0

I use varnish 4, php-fpm 7, nginx, centos 7

My varnish.params:

DAEMON_OPTS="-a :80 -T 127.0.0.1:6082 
             -f /etc/varnish/default.vcl 
             -S /etc/varnish/secret 
             -s malloc,1g 
             -p feature=+esi_disable_xml_check,+esi_ignore_other_elements 
             -p cli_buffer=16384 
             -p vcc_allow_inline_c=on"

My default.vcl:

if (bereq.url ~ "^.*(\/**esi**\/)+.*$") {
   set beresp.do_esi = true;
   set beresp.ttl = 0s;
} else { 
   set beresp.ttl = 3600s;
}

My problem is when i use that vcl code which is triggered by accessing say it: http://localhost/lab/varnish

Which render:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
</head>
<body>
    <esi:include src="http://localhost/lab/esi/body"/>
</body>
</html>

Varnish is not reading the url src inside the ESI tag, so it's just rendering an empty body.

But when i use this code:

if (bereq.url ~ "^.*(\/**lab**\/)+.*$") {
   set beresp.do_esi = true;
   set beresp.ttl = 0s;
} else { 
   set beresp.ttl = 3600s;
}

Varnish successfully render the content inside ESI tag which is produced by: http://localhost/lab/esi/body

How to make Varnish trigger the ESI fragment render based on recognizing what is in ESI "src" tag?

I've tried setting Surrogate-Capability and checking with Surrogate-Control, it's not working either, for me. I'm running out of clue..

Yoga Fishguts
  • 116
  • 1
  • 7

1 Answers1

0

I don't think you can.

If you set beresp.do_esi to true, Varnish will parse the backend response and replace each esi:include tag by its source content.

If you don't Varnish will not parse the beresp and serve it to the client as is.

By the way why do you want to partially replace esi tags?

Benjamin Baumann
  • 4,035
  • 2
  • 25
  • 35
  • I want varnish to use the already cached content to serve to the client, and exclude (request to backend) content only from the source inside the ESI tag.. can it be done? – Yoga Fishguts Apr 07 '17 at 05:45