Varnish for web developers

Author

Kacper Wysocki

Contact

kwy@redpill-linpro.com

Date

November 24, 2010

I already have $CACHE. Why Varnish?

img/invaders.gif

There are no silver bullets

Usually we use varnish to:

img/quadsm2.jpg

Logistics

setup varnish

apt-get install varnish
yum install varnish
img/shipping.jpg

features covered

img/fight-club-soap.jpg

side note: backend definition

do this now:

backend mine {
  .host = "my backend";
  .port = "80";
}
img/truck.jpg

what to cache

img/bike.jpg

what to cache cont'd

img/energy.jpg

how to cache

img/child_smiles.jpg

What about...

img/pat.jpg

Purging pages

img/notbutter.jpg

Purging pages cont'd

purges: excersizeamples

purge req.url ~ "/foo"
purge req.http.user-agent ~ "Firefox" &&
      obj.http.content-type ~ "text"
purge("req.url == " req.url);
img/frying.jpg

Edge Side Includes

Benefits:

ESI cont'd

Limitations:

Enable ESI

sub vcl_fetch {
   if(obj.http.content-type ~ "text/html"){
     esi;
   }
}
img/destruction.jpg

Practical ESI

<html>
<body>
Foobar
<esi:include src="http://kwy.u.bitbit.net/">
<esi:include src="/cgi-bin/date.cgi">
</body>
img/advertising.gif

More ESI

<esi:include src="/must/be/reachable/thru/backends/">
<esi:remove>not shown if ESI on</esi:remove>
<!--esi not shown if ESI is off -->

Questions?

kacper.blog.linpro.no

kwy.u.bitbit.net

kwy@redpill-linpro.com

6BD0 3F9C 5F77 AD24 F60A
86EC FD82 7E34 674A 506F

References: http://www.varnish-cache.org/trac/wiki