<div>Would someone here help me with using VCL for a complex situation with Varnish?</div><div><br></div>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:<div>
<br></div><div>1. Using VCL to have a list of 3 backend address:</div><div> <a href="http://m.com">m.com</a></div><div> <a href="http://s01.com">s01.com</a></div><div> <a href="http://s02.com">s02.com</a></div>
<div><br></div><div>2. Configure Varnish so that:</div><div> a. it relays each of incoming GET requests to the master backend (<a href="http://m.com">m.com</a>, in this case), and the master backend (<a href="http://m.com">m.com</a>) will always respond with a status 302 for redirect.</div>
<div><br></div><div> 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 <a href="http://s01.com">s01.com</a> or <a href="http://s02.com">s02.com</a>), and restart the fetch to let Varnish fetch the request from the slave backend.</div>
<div><br></div><div><br></div><div>I have tried to construct a VCL (included at the bottom) but I am unable to make Varnish work the exactly as described above.</div><div><br></div><div>FYI, I am using Varnish 2.1.3.</div>
<div><br></div><div>Any help would appreciated very much,</div><div><br></div><div>--Joe</div><div><br></div><div>backend b_m {</div><div> .host = "<a href="http://m.com">m.com</a>";</div><div> .port = "80";</div>
<div>}</div><div><br></div><div>backend b1 {</div><div> .host = "<a href="http://s01.com">s01.com</a>";</div><div> .port = "80";</div><div>}</div><div><br></div><div>backend b2 {</div><div>
.host = "<a href="http://s02.com">s02.com</a>";</div><div> .port = "80";</div><div>}</div><div><br></div><div><br></div><div>sub vcl_recv {</div><div> if (!(req.url ~ "(.*s0.*)") && req.url ~ "(.*e\.html)") {</div>
<div> set req.backend = b_m;</div><div> set req.http.host = "<a href="http://m.com">m.com</a>";</div><div> }</div><div>}</div><div><br></div><div>sub vcl_fetch {</div><div> if (beresp.status == 302) {</div>
<div> if (beresp.http.location ~ "(.*s01.*)" ) {</div><div> set req.backend = b1;</div><div> set req.url = beresp.http.location;</div><div> set req.http.host = "<a href="http://s01.a.com">s01.a.com</a>";</div>
<div> }</div><div> else if (beresp.http.location ~ "(.*s02.*)" ) {</div><div> set req.backend = b2;</div><div> set req.url = beresp.http.location;</div><div> set req.http.host = "<a href="http://s02.com">s02.com</a>";</div>
<div> }</div><div> }</div><div><br></div><div> restart;</div><div>}</div><div> </div><div><br></div>