4

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.

Charles
  • 50,943
  • 13
  • 104
  • 142
Jacob
  • 91
  • 1
  • 4
  • I'm using version varnish-2.1.5 – Jacob Apr 01 '11 at 04:30
  • 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 Apr 01 '11 at 05:41
  • 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 Apr 01 '11 at 05:55
  • I do see this in varnishlog. 11 VCL_error c esi can only be called from vcl_fetch – Jacob Apr 01 '11 at 05:57
  • Sorry that's an incorrect error message. This is the correct one: ESI_xmlerror c No ESI processing, first char not '<' – Jacob Apr 01 '11 at 06:05
  • So I know nothing about Varnish other than what it is and does, but it seems to me, from that error, that it's not seeing your `sub vcl_fetch` block and/or not understanding that you're asking it to process the include from `test.php`. – Charles Apr 01 '11 at 06:06

4 Answers4

5

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.

Jacob
  • 91
  • 1
  • 4
1

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

For Varnish 3.x

in vcl_fetch, I had to add:

set beresp.do_esi = true;
NeuroScr
  • 322
  • 1
  • 7
0

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.

Charles
  • 50,943
  • 13
  • 104
  • 142