Using varnish as a cache for more than one website
Davies Matt J A (LCSS)
mjdavies at glam.ac.uk
Tue Jun 29 12:32:56 CEST 2010
Thanks Marcus
I got there in the end with the documentation, wonderful stuff :-)
backend a {
.host = "machinename";
.port = "80";
}
backend b {
.host = "machinename";
.port = "8082";
}
#
#Below is a commented-out copy of the default VCL logic. If you
#redefine any of these subroutines, the built-in logic will be
#appended to your code.
#
sub vcl_recv {
if (req.http.host == "a.com") {
set req.backend = a;
}
if (req.http.host == "b.com") {
set req.backend = b;
}
if (req.url ~ "^/") {
unset req.http.cookie;
}
}
sub vcl_fetch {
if (req.url ~ "^/") {
unset obj.http.set-cookie;
set obj.ttl = 600s;
}
}
BTW, is it good form to reply to the list or the person who replied? Told you I was green :-)
Matt
On 29 Jun 2010, at 11:23, Marcus Smith wrote:
> Davies Matt J A (LCSS) wrote:
>> Hello everyone
>>
>> What is the best practice way of setting up varnish to act as a cache
>> for more than one web site?
>>
>> I can see I can make multiple backend, and I've read that I can run
>> multiple instances of varnish, I'm just wondering what is the best
>> practice way?
>>
>> One thing I can't quite get my head around is how do I tell varnish
>> which incoming URL to serve with which backend, or instance.
>>
>> Scenario
>>
>> I've got our DNS boys to point a.com and b.com at our varnish server,
>> which is going to act as a cache for both sites, both sites being
>> very different and needing different rules. Rules that may collide
>> also.
>>
>> If I use the multiple instance route, how do associate an instance
>> with an incoming URL?
>
> With a single instance of varnish, having defined your back ends, you
> might for example do something like this:
>
>
> sub vcl_recv {
> if (req.http.host == "a.com") {
> set req.backend = backend-A;
> # More site-specific rules here
> }
>
> elsif (req.http.host ~ "(www\.)?b\.com") {
> set req.backend = backend-B;
> # More site-specific rules here
> }
>
> # More sites here
>
> else {
> error 404 "Unknown host!";
> }
> }
>
>
> best wishes,
> Marcus
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at varnish-cache.org
> http://lists.varnish-cache.org/mailman/listinfo/varnish-misc
More information about the varnish-misc
mailing list