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
You can use Varnish to cache both dynamic and static content: this is an efficient solution to increase not only your website speed but also your server performance. According to its developers: “It can speed up delivery with a factor of 300 – 1000x, depending on your architecture.
Bypassing the cache in Varnish is done by calling return (pass) in the vcl_recv subroutine of your VCL file. This return statement will send you to the vcl_pass subroutine where a backend fetch will be triggered instead of performing a cache lookup.
Varnish cache is a web application accelerator also known as caching HTTP reverse proxy. It acts more like a middle man between your client (i.e. user) and your web server. That means, instead of your web server to directly listen to requests of specific contents all the time, Varnish will assume the responsibility.
Varnish will, in the default configuration, not cache a object coming from the backend with a Set-Cookie header present. Also, if the client sends a Cookie header, Varnish will bypass the cache and go directly to the backend.
(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;
}
}
And in varnish3-vcl:
sub vcl_recv {
# dont cache foo.com or bar.com - optional www
if (req.http.host ~ "(www\.)?(foo|bar)\.com") {
return(pass);
}
# cache foobar.com - optional www
if (req.http.host ~ "(www\.)?foobar\.com") {
return(lookup);
}
}
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 (req.host ~ "(www)?(foo|bar).com") {
return(pass);
}
}
replace lookup with hash
default.vcl:
sub vcl_recv {
# dont cache foo.com or bar.com - optional www
if (req.http.host ~ "(www\.)?(foo|bar)\.com") {
return(pass);
}
# cache foobar.com - optional www
if (req.http.host ~ "(www\.)?foobar\.com") {
return(hash);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With