Varnish Cache will not do ESI include

5.5k Views Asked by At

I am having problems getting even the simplest of Varnish Cache ESI tests to work.
After trying and trying I thought I ask here.

Basically it just wont include the ESI file. It's just returning the HTML without doing it's include.

Here is my varnish start command:

varnishd -f /etc/varnish/default.vcl -s malloc,128M -T 127.0.0.1:2000 -a 0.0.0.0:8080;

Here is the URL I'm testing with:

http://vbox.local:8080/varnish-tests/test.php

My vcl rules:

1) default.vcl

backend default {  
.host = "127.0.0.1";  
.port = "80";  
}  

sub vcl_fetch {  

  if (req.url ~ "test.php") {  
      esi;  /* Do ESI processing */  
      set beresp.ttl = 24h;  
  } elseif (req.url ~ "esi_1.php") {  
      set beresp.ttl = 1m;  
  }  
return(deliver);  
}  

My sample test esi code

2) test.php

<html>  
<head>  

<?php echo "Time 1: ".time(); ?>  

<br />  

The time 2 is: <esi:include src="/varnish-tests/esi_1.php"/> at this very moment.  

</body>  
</html>  

The php to esi include

3) esi_1.php

<?php
echo "Time 2: ".time();  
?>

I've tried many variations of the above vcl rules.
All don't work. Just can't see where I'm going wrong?

Any advise/help much appreciated.

Thank you.

4

There are 4 best solutions below

0
On

Given the newest error, this blog post may be relevant.

It seems that certain versions of Varnish don't handle gzipped content well. Do you have PHP set to perform gzip compression? Do you have the web server software hosting PHP set to perform gzip compression?

Varnish also can choke over poorly-formed content, though that doesn't seem to be likely here...

Unfortunately I'm now out of ideas.

1
On

The problem is Varnish and mod_deflate don't work together well at this time.

Removing deflate.conf and deflate.load fixed the problem.

Cheers.

0
On

For Varnish 3.x

in vcl_fetch, I had to add:

set beresp.do_esi = true;
0
On

Try testing with Varnish 3.0 beta1. One of its main new features is full compression support (which means that it now works also with ESI):

https://www.varnish-software.com/blog/varnish-cache-30-beta-1-out

With that you'll probably avoid changing anything on your apache/php compression handling settings.