<div dir="ltr">You must set up one director for each set of vhosts that you are planning to serve. You can't just chuck all the backends into one director.<div><br></div><div><br></div><div>Per.</div></div><div class="gmail_extra">

<br><br><div class="gmail_quote">On Fri, Aug 30, 2013 at 1:50 PM, Tharanga Abeyseela <span dir="ltr"><<a href="mailto:tharanga.abeyseela@gmail.com" target="_blank">tharanga.abeyseela@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Thanks for the info. But in this way you can't do the round-robin loadblancing right . actually i need to use the varnish (<a href="http://cluster.com/80" target="_blank">cluster.com/80</a>) and redirect requests to both back-ends in round-robin fashion. <br>


<br></div>request ---> varnish (<a href="http://cluster.com" target="_blank">cluster.com</a>)  ---RR-loadblance---> <a href="http://xxx.com" target="_blank">xxx.com</a> and <a href="http://yyyy.com" target="_blank">yyyy.com</a><br>

<br></div>I'm not looking to send the request to <a href="http://xxx.com" target="_blank">xxx.com</a> or <a href="http://yyy.com" target="_blank">yyy.com</a> directly. im sending the reuquest to <a href="http://cluter.com" target="_blank">cluter.com</a> that is my vanrish server listing on port 80.<br>


<br></div>Thanks,<br></div>Tharanga<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 30, 2013 at 9:35 PM, Per Buer <span dir="ltr"><<a href="mailto:perbu@varnish-software.com" target="_blank">perbu@varnish-software.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Tharanga,<div><br></div><div>You seem not to understand. Varnish will just pass the host header in the request to the backend you specify. Looking at the VCL you provided you put both the backends into one director. This is probably not what you want to do.</div>




<div><br></div><div>Try removing the director. Name the directors xxx and yyy and have the VCL look like.</div><div><br></div><div><pre style="white-space:pre-wrap;color:rgb(80,0,80)">sub vcl_recv {
    if (req.http.host ~ "<a href="http://xxx.com" target="_blank">xxx.com</a>") {</pre><pre style="white-space:pre-wrap;color:rgb(80,0,80)">        req.backend = xxx;</pre><pre style="white-space:pre-wrap;color:rgb(80,0,80)">

    } else if (..</pre>

<pre style="white-space:pre-wrap;color:rgb(80,0,80)"><br></pre><pre style="white-space:pre-wrap;color:rgb(80,0,80)">}</pre>Also the next bit doesn't make sense:<pre style="white-space:pre-wrap;color:rgb(80,0,80)">if (req.request)
    {
    return(pass);
    }

}</pre></div></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 30, 2013 at 10:42 AM, Tharanga Abeyseela <span dir="ltr"><<a href="mailto:tharanga.abeyseela@gmail.com" target="_blank">tharanga.abeyseela@gmail.com</a>></span> wrote:<br>




<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi,<br><br>Actually i tried that link, still it is not working. it should work for a ip based virtual host, but namebased virtual host is not working.<br>




</div>becuase main request coming to varnish/80 and varnish should redirect the traffic to the backend server based on my round-robin director. when you resolve dns for those two hosts (<a href="http://xxx.com" target="_blank">xxx.com</a> and <a href="http://yyy.com" target="_blank">yyy.com</a>) it reuturns the same IP. that is 192.168.0.100. But there should be a way to send the host-header to apache. Not sure how it works here. But when i use different server (192,168.0.200/ <a href="http://zzz.com" target="_blank">zzz.com</a>) it works without any issue, it roundrobin the traffic. This is an issue with namebased virtualhost. <br>





<br></div><div>varnish recevie the traffic (<a href="http://cluster.com" target="_blank">cluster.com</a> is my  varnish server), then it use it vcl to redirect based on my round-robin setting. but how it can send the traffic to the correct virtualhost. because it gets only the same IP address from the DNS. I managed to change the default behaviour by forcefully setting the host-header as follows to my other virtualhost(yyy..com)<br>





</div><div>set.req.host="<a href="http://yyy.com" target="_blank">yyy.com</a>" ;<br></div><div>then all request went to <a href="http://yyy.com" target="_blank">yyy.com</a> instead of <a href="http://xxx.com" target="_blank">xxx.com</a>. but what i want is  a round-robin fashio...to send traffic. first req to <a href="http://xxx.com/" target="_blank">xxx.com/</a> 2nd req to <a href="http://yyy.com" target="_blank">yyy.com</a> and so on..<br>





</div><div><br></div>I was trying to find some resourses on the net, stackoverflow etc..but no luck yet. <br><div><br><br></div><div>Thanks again for your help <br></div><div>Cheers,<br></div><div>Tharanga<br></div></div>




<div><div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 30, 2013 at 5:05 PM, Per Buer <span dir="ltr"><<a href="mailto:perbu@varnish-software.com" target="_blank">perbu@varnish-software.com</a>></span> wrote:<br>





<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Tharanga,<div><br></div><div>You seem to be a bit confused about how the directors and backends work in Varnish. Please read this:</div>





<div><br></div><div><a href="https://www.varnish-cache.org/docs/trunk/users-guide/vcl-backends.html#backends-and-virtual-hosts-in-varnish" target="_blank">https://www.varnish-cache.org/docs/trunk/users-guide/vcl-backends.html#backends-and-virtual-hosts-in-varnish</a><br>







</div><div><br></div><div>Note that the .host property of the backend has NOTHING to do with the virtual host.</div></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 30, 2013 at 2:02 AM, Tharanga Abeyseela <span dir="ltr"><<a href="mailto:tharanga.abeyseela@gmail.com" target="_blank">tharanga.abeyseela@gmail.com</a>></span> wrote:<br>







<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div>Hi Per,<br><br></div>Thanks for the reply. Actually my set up looks like this.<br>







<br><br></div><a href="http://cluster.com" target="_blank">cluster.com</a> - 192.168.0.200 (varnish/port 80)<br>
</div><a href="http://xxx.com" target="_blank">xxx.com</a> - 192.168.0.100  (apache,namebased vhost/8080 - backendname - website)<br></div><a href="http://yyy.com" target="_blank">yyy.com</a> - 192.168.0.100  (apache,namebased vhost/8080 -backendname - api)<br>








<br></div><div><a href="http://cluster.com" target="_blank">cluster.com</a> is the varnish server and front-end connections coming to this and rewrite to other defined back-ends (round-robin based balancing)<br></div><div>







<div><span style="text-indent:0px;letter-spacing:normal;font-variant:normal;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:medium;white-space:normal;font-family:'Times New Roman';word-spacing:0px"><pre style="white-space:pre-wrap">



backend website {
    .host = "<a href="http://xxx.com" target="_blank">xxx.com</a>";
    .port = "8080";

}
backend api {
    .host = "<a href="http://yyy.com" target="_blank">yyy.com</a>";
    .port = "8080";

}

director clust round-robin {
{ .backend = api;  }
{ .backend = website;  }

}

sub vcl_recv {
set req.backend = clust;
if (req.request)
    {
    return(pass);
    }

}
</pre></span><br></div></div>when i hit the <a href="http://cluster.com" target="_blank">cluster.com</a> , it is always going to <a href="http://xxx.com" target="_blank">xxx.com</a>, but what i need to do is first request go to <a href="http://xxx.com" target="_blank">xxx.com</a> second request <a href="http://yyy.com" target="_blank">yyy.com</a> and so on...when i add another server (different host/different IP say <a href="http://192.168.0.111/zzz.com" target="_blank">192.168.0.111/zzz.com</a>, and a different backend) , it goes like this<br>








<br></div>first request - <a href="http://xxx.com" target="_blank">xxx.com</a><br></div>second request - <a href="http://xxxx.com" target="_blank">xxxx.com</a><br></div>third request - <a href="http://zzz.com" target="_blank">zzz.com</a><br>







<br><br></div>but i can change the default behavior by setting up set req.host = <a href="http://yyy.com" target="_blank">yyy.com</a> and then it will goes to <br>
</div>first request - <a href="http://yyy.com" target="_blank">yyy.com</a><br>second request - <a href="http://yyy.com" target="_blank">yyy.com</a><br></div>third request - <a href="http://zzz.com" target="_blank">zzz.com</a><br>







<br></div>this is something to do with the host-header forwarding to the correct back-end. how should i add that functionality to the vcl_recv ?<br>
</div>appreciate your help on this, this is working perfectly with other servers (different servers, not with namebased vhosts)<br><br></div>cheers,<br></div>Tharanga  <br><div><div><div><div><div><br>  <br><div><div><div>








<div><div><div><div><br><br><br><br><br><div><div><div><div><br><br><br><br><br><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><div><div>

<div class="gmail_extra"><br><br><div class="gmail_quote">
On Thu, Aug 29, 2013 at 11:58 PM, Per Buer <span dir="ltr"><<a href="mailto:perbu@varnish-software.com" target="_blank">perbu@varnish-software.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">








<div dir="ltr">Hi mate,<br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 29, 2013 at 3:17 PM, Tharanga Abeyseela <span dir="ltr"><<a href="mailto:tharanga.abeyseela@gmail.com" target="_blank">tharanga.abeyseela@gmail.com</a>></span> wrote:<br>










<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">(..)<div><br>But how should i send host-headers to varnish to redirect to the correct server, This is always going to <a href="http://xxx.com" target="_blank">xxx.com</a>.<br>










</div></div></blockquote><div><br></div><div>You don't. :-)</div><div><br></div><div>You need to dispatch the request to the right backend in vcl_recv and have the backend handle that host. You could start rewriting the host in vcl_recv, but I would advise against it. </div>










<div><br></div><div>So, if you have two vhosts handled by "website" you just set that as the backend in vcl_recv.</div></div><span><font color="#888888"><div><br></div>-- <br><div dir="ltr"><div style="color:rgb(34,34,34);font-size:12.727272033691406px;font-family:arial,sans-serif;margin:5px 15px 0px 0px;padding-bottom:5px">










<table style="text-align:start;font-size:12px;line-height:1.5em;font-family:'Helvetica Neue',Arial,sans-serif;color:rgb(102,102,102);width:550px;border-top-width:1px;border-top-style:solid;border-top-color:rgb(238,238,238);border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);margin-top:20px;padding-top:5px;padding-bottom:5px" border="0" cellpadding="0" cellspacing="0">










<tbody><tr><td style="font-family:arial,sans-serif;margin:0px" width="100"><a href="http://www.varnish-software.com/" style="color:rgb(17,85,204)" target="_blank"><img src="http://www.varnish-software.com/static/media/logo-email.png" style="float:left;margin-left:10px"></a></td>










<td style="font-family:arial,sans-serif;margin:0px"><b style="font-size:14px;color:rgb(34,34,34)">Per Buer</b><br>CTO | Varnish Software AS<br>Phone: <a href="tel:%2B47%20958%2039%20117" value="+4795839117" target="_blank">+47 958 39 117</a> | Skype: per.buer<br>








<span style="font-weight:bold">We Make Websites Fly!<br>

<br></span><span style="font-family:'Helvetica Neue',Arial,sans-serif;font-size:14px;font-weight:bold">Winner of the Red Herring Top 100 Europe Award 2013<br></span><p style="margin:0px;line-height:normal;font-family:Helvetica">










<img src="https://www.varnish-software.com/sites/default/files/redherring_2013_winner_sml.jpg"></p><span style="font-weight:bold"><br></span></td></tr></tbody></table><div></div></div><div style="clear:both;color:rgb(34,34,34);font-size:12.727272033691406px;font-family:arial,sans-serif;margin:15px 0px">










</div></div>
</font></span></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div style="color:rgb(34,34,34);font-size:12.727272033691406px;font-family:arial,sans-serif;margin:5px 15px 0px 0px;padding-bottom:5px">







<table style="text-align:start;font-size:12px;line-height:1.5em;font-family:'Helvetica Neue',Arial,sans-serif;color:rgb(102,102,102);width:550px;border-top-width:1px;border-top-style:solid;border-top-color:rgb(238,238,238);border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);margin-top:20px;padding-top:5px;padding-bottom:5px" border="0" cellpadding="0" cellspacing="0">







<tbody><tr><td style="font-family:arial,sans-serif;margin:0px" width="100"><a href="http://www.varnish-software.com/" style="color:rgb(17,85,204)" target="_blank"><img src="http://www.varnish-software.com/static/media/logo-email.png" style="float:left;margin-left:10px"></a></td>







<td style="font-family:arial,sans-serif;margin:0px"><b style="font-size:14px;color:rgb(34,34,34)">Per Buer</b><br>CTO | Varnish Software AS<br>Phone: <a href="tel:%2B47%20958%2039%20117" value="+4795839117" target="_blank">+47 958 39 117</a> | Skype: per.buer<br>





<span style="font-weight:bold">We Make Websites Fly!<br>

<br></span><span style="font-family:'Helvetica Neue',Arial,sans-serif;font-size:14px;font-weight:bold">Winner of the Red Herring Top 100 Europe Award 2013<br></span><p style="margin:0px;line-height:normal;font-family:Helvetica">







<img src="https://www.varnish-software.com/sites/default/files/redherring_2013_winner_sml.jpg"></p><span style="font-weight:bold"><br></span></td></tr></tbody></table><div></div></div><div style="clear:both;color:rgb(34,34,34);font-size:12.727272033691406px;font-family:arial,sans-serif;margin:15px 0px">







</div></div>
</div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div style="color:rgb(34,34,34);font-size:12.727272033691406px;font-family:arial,sans-serif;margin:5px 15px 0px 0px;padding-bottom:5px">




<table style="text-align:start;font-size:12px;line-height:1.5em;font-family:'Helvetica Neue',Arial,sans-serif;color:rgb(102,102,102);width:550px;border-top-width:1px;border-top-style:solid;border-top-color:rgb(238,238,238);border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);margin-top:20px;padding-top:5px;padding-bottom:5px" border="0" cellpadding="0" cellspacing="0">




<tbody><tr><td style="font-family:arial,sans-serif;margin:0px" width="100"><a href="http://www.varnish-software.com/" style="color:rgb(17,85,204)" target="_blank"><img src="http://www.varnish-software.com/static/media/logo-email.png" style="float:left;margin-left:10px"></a></td>




<td style="font-family:arial,sans-serif;margin:0px"><b style="font-size:14px;color:rgb(34,34,34)">Per Buer</b><br>CTO | Varnish Software AS<br>Phone: <a href="tel:%2B47%20958%2039%20117" value="+4795839117" target="_blank">+47 958 39 117</a> | Skype: per.buer<br>


<span style="font-weight:bold">We Make Websites Fly!<br>

<br></span><span style="font-family:'Helvetica Neue',Arial,sans-serif;font-size:14px;font-weight:bold">Winner of the Red Herring Top 100 Europe Award 2013<br></span><p style="margin:0px;line-height:normal;font-family:Helvetica">




<img src="https://www.varnish-software.com/sites/default/files/redherring_2013_winner_sml.jpg"></p><span style="font-weight:bold"><br></span></td></tr></tbody></table><div></div></div><div style="clear:both;color:rgb(34,34,34);font-size:12.727272033691406px;font-family:arial,sans-serif;margin:15px 0px">




</div></div>
</div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div style="font-size:12.727272033691406px;margin:5px 15px 0px 0px;padding-bottom:5px;color:rgb(34,34,34);font-family:arial,sans-serif;background-color:rgb(255,255,255)">

<table border="0" cellpadding="0" cellspacing="0" style="text-align:start;font-size:12px;line-height:1.5em;font-family:'Helvetica Neue',Arial,sans-serif;color:rgb(102,102,102);width:550px;border-top-width:1px;border-top-style:solid;border-top-color:rgb(238,238,238);border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);margin-top:20px;padding-top:5px;padding-bottom:5px">

<tbody><tr><td width="100" style="font-family:arial,sans-serif;margin:0px"><a href="http://www.varnish-software.com/" style="color:rgb(17,85,204)" target="_blank"><img src="http://www.varnish-software.com/static/media/logo-email.png" style="float:left;margin-left:10px"></a></td>

<td style="font-family:arial,sans-serif;margin:0px"><b style="font-size:14px;color:rgb(34,34,34)">Per Buer</b><br>CTO | Varnish Software AS<br>Phone: +47 958 39 117 | Skype: per.buer<br><span style="font-weight:bold">We Make Websites Fly!<br>

<br></span><span style="font-family:'Helvetica Neue',Arial,sans-serif;font-size:14px;font-weight:bold">Winner of the Red Herring Top 100 Europe Award 2013<br></span><p style="margin:0px;line-height:normal;font-family:Helvetica">

<img src="https://www.varnish-software.com/sites/default/files/redherring_2013_winner_sml.jpg"></p><span style="font-weight:bold"><br></span></td></tr></tbody></table><div></div></div><div style="font-size:12.727272033691406px;margin:15px 0px;clear:both;color:rgb(34,34,34);font-family:arial,sans-serif;background-color:rgb(255,255,255)">

</div></div>
</div>