4
votes

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
I'm using version varnish-2.1.5 - Jacob
What do you mean by "it doesn't work." What happens? Does the include not get processed? Does the tag appear in the HTML you get in your browser? Does it get replaced with nothing? Is there an error log to check? Does the backend server running PHP get the proper entries in it's access log? - Charles
Hi, Yes the tag appears on the HTML the browser receives. It's not replaced at all. There are no errors logged in PHP. The PHP access log gets only the hit to test.php and nothing to esi_1.php. - Jacob
I do see this in varnishlog. 11 VCL_error c esi can only be called from vcl_fetch - Jacob
Sorry that's an incorrect error message. This is the correct one: ESI_xmlerror c No ESI processing, first char not '<' - Jacob

4 Answers

5
votes

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.

1
votes

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.

0
votes

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.

0
votes

For Varnish 3.x

in vcl_fetch, I had to add:

set beresp.do_esi = true;