Varnish round-robin loadbalancing with Virtualhost (Namebased)

Per Buer perbu at varnish-software.com
Fri Aug 30 09:05:13 CEST 2013


Hi Tharanga,

You seem to be a bit confused about how the directors and backends work in
Varnish. Please read this:

https://www.varnish-cache.org/docs/trunk/users-guide/vcl-backends.html#backends-and-virtual-hosts-in-varnish

Note that the .host property of the backend has NOTHING to do with the
virtual host.


On Fri, Aug 30, 2013 at 2:02 AM, Tharanga Abeyseela <
tharanga.abeyseela at gmail.com> wrote:

> Hi Per,
>
> Thanks for the reply. Actually my set up looks like this.
>
>
> cluster.com - 192.168.0.200 (varnish/port 80)
> xxx.com - 192.168.0.100  (apache,namebased vhost/8080 - backendname -
> website)
> yyy.com - 192.168.0.100  (apache,namebased vhost/8080 -backendname - api)
>
> cluster.com is the varnish server and front-end connections coming to
> this and rewrite to other defined back-ends (round-robin based balancing)
>
>
> backend website {
>     .host = "xxx.com";
>     .port = "8080";
>
> }
> backend api {
>     .host = "yyy.com";
>     .port = "8080";
>
> }
>
> director clust round-robin {
> { .backend = api;  }
> { .backend = website;  }
>
> }
>
> sub vcl_recv {
> set req.backend = clust;
> if (req.request)
>     {
>     return(pass);
>     }
>
> }
>
>
> when i hit the cluster.com , it is always going to xxx.com, but what i
> need to do is first request go to xxx.com second request yyy.com and so
> on...when i add another server (different host/different IP say
> 192.168.0.111/zzz.com, and a different backend) , it goes like this
>
> first request - xxx.com
> second request - xxxx.com
> third request - zzz.com
>
>
> but i can change the default behavior by setting up set req.host = yyy.comand then it will goes to
> first request - yyy.com
> second request - yyy.com
> third request - zzz.com
>
> 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 ?
> appreciate your help on this, this is working perfectly with other servers
> (different servers, not with namebased vhosts)
>
> cheers,
> Tharanga
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> On Thu, Aug 29, 2013 at 11:58 PM, Per Buer <perbu at varnish-software.com>wrote:
>
>> Hi mate,
>>
>> On Thu, Aug 29, 2013 at 3:17 PM, Tharanga Abeyseela <
>> tharanga.abeyseela at gmail.com> wrote:
>>
>>> (..)
>>>
>>> But how should i send host-headers to varnish to redirect to the correct
>>> server, This is always going to xxx.com.
>>>
>>
>> You don't. :-)
>>
>> 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.
>>
>> So, if you have two vhosts handled by "website" you just set that as the
>> backend in vcl_recv.
>>
>> --
>>  <http://www.varnish-software.com/> *Per Buer*
>> CTO | Varnish Software AS
>> Phone: +47 958 39 117 | Skype: per.buer
>> We Make Websites Fly!
>>
>> Winner of the Red Herring Top 100 Europe Award 2013
>>
>>
>>
>


-- 
 <http://www.varnish-software.com/> *Per Buer*
CTO | Varnish Software AS
Phone: +47 958 39 117 | Skype: per.buer
We Make Websites Fly!

Winner of the Red Herring Top 100 Europe Award 2013
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20130830/8ca799c9/attachment.html>


More information about the varnish-misc mailing list