views:

70

answers:

2

Hello,

I have been Googling aggressively, but without luck.

I'm using Varnish with great results, but I would like to host multiple websites on a single server (Apache), without Varnish caching all of them.

Can I specify what websites by URL to cache?

Thanks

A: 

Yes,

in vcl_recv you just match the hosts that you would like not to cache and pass them. Something like this (untested):

vcl_recv {
   # dont cache foo.com or bar.com - optional www
   if (reg.host ~ "(www)?(foo|bar).com") {
     return(pass);
   }
}
perbu
+1  A: 

(edited after comment) It's req.http.host, so in your vcl file (e.g. default.vcl) do:

sub vcl_recv {
  # dont cache foo.com or bar.com - optional www
   if (req.http.host ~ "(www)?\.(foo|bar)\.com") {
     pass;
   }
  # cache foobar.com - optional www
   if ( req.http.host ~ "(www)?\.foobar\.com" ) {
     lookup;
   }
}
ivy
Great, pointed me in the right direction I think. But isn't it req.http.host? http://www.varnish-cache.org/trac/wiki/VCL
Rune
You're right, thanks! It's req.http.host (and req.url). I fixed it in the example.
ivy