Complex Backend Selection through VCL?
Joe Chen
joec1502 at gmail.com
Sat Aug 7 00:50:09 CEST 2010
Would someone here help me with using VCL for a complex situation with
Varnish?
I was ask to configure Varnish within using VCL to do a very dynamic backend
selection process, but unable to achieve that. The task I was given is:
1. Using VCL to have a list of 3 backend address:
m.com
s01.com
s02.com
2. Configure Varnish so that:
a. it relays each of incoming GET requests to the master
backend (m.com, in this case), and the master backend (m.com) will always
respond with a status 302 for redirect.
b. for each of fetched 302 from master backend, Varnish will
check the http header and to select a corresponding slave backend from the
the list( either s01.com or s02.com), and restart the fetch to let Varnish
fetch the request from the slave backend.
I have tried to construct a VCL (included at the bottom) but I am unable to
make Varnish work the exactly as described above.
FYI, I am using Varnish 2.1.3.
Any help would appreciated very much,
--Joe
backend b_m {
.host = "m.com";
.port = "80";
}
backend b1 {
.host = "s01.com";
.port = "80";
}
backend b2 {
.host = "s02.com";
.port = "80";
}
sub vcl_recv {
if (!(req.url ~ "(.*s0.*)") && req.url ~ "(.*e\.html)") {
set req.backend = b_m;
set req.http.host = "m.com";
}
}
sub vcl_fetch {
if (beresp.status == 302) {
if (beresp.http.location ~ "(.*s01.*)" ) {
set req.backend = b1;
set req.url = beresp.http.location;
set req.http.host = "s01.a.com";
}
else if (beresp.http.location ~ "(.*s02.*)" ) {
set req.backend = b2;
set req.url = beresp.http.location;
set req.http.host = "s02.com";
}
}
restart;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-dev/attachments/20100806/4ed1872d/attachment-0003.html>
More information about the varnish-dev
mailing list