AW: Loadbalancing with 301 / 302

Enno van Amerongen enno at tty.nl
Thu Jul 28 15:45:23 CEST 2011


(please keep the discussion on the mailinglist, so others can benefit
from it too)

I'd say you're trying to use the wrong tool for the job. If its possible
at all, it'll require some hefty vcl though, or inline C, or a vmod...

what you want to do is:
 - abuse varnish backend polling, so you can pick the next healthy
backend, and use it in a redirect
 - rewrite the request to use the hostname from varnish backend
configuration and send a 301

what you dont want to do is:
 - use varnish as its meant to be: an http accelerating caching proxy
 - use caching
 - use proxying

you can btw use errors to force a reply in varnish:

sub vcl_recv {
    if (req.http.host ~ "^img\.test\.com$") {
        error 301;
    }
}

sub vcl_error {
    if (obj.status == 301) {
        # now, I dont know how you could get the current healthy
backends and use the host to set:
        set obj.http.host = 'img2.test.com';
        return (deliver);
    }
}

maybe someone else knows how to get the next backend, if possible at all...

Enno

Carsten Dietz wrote:
> Hi Enno,
>
> yes I do copy past.
> My problem is that I don’t have an idea how much I can do in varnish with
> varnish code.
> With lookup the varnish-server seems to download the requestet file and send
> it to the "Requester".
> But I want to give the "Requester" only a 301 / 302 with a new url, because
> of traffic Limitations.
> I can can handle this be an external script ok but this isn't the fastest
> way.
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: varnish-misc-bounces at varnish-cache.org
> [mailto:varnish-misc-bounces at varnish-cache.org] Im Auftrag von Enno van
> Amerongen
> Gesendet: Donnerstag, 28. Juli 2011 14:27
> An: varnish-misc at varnish-cache.org
> Betreff: Re: Loadbalancing with 301 / 302
>
> Hi,
>
> First of all, if you get an error, tell us what it is.
>
> Second, you seem to have copypasted the healthchecks directly from the
> docs, not sure if it works or if its a typo in the docs, but I'd say:
> .timeout = 1s (without the space)
>
> Third, your vcl_recv is wrong, try:
>
> sub vcl_recv {
>     set req.backend = baz;
>     return (lookup);
> }
>
> good luck!
>
> Carsten Dietz wrote:
>   
>> Hi,
>>
>>  
>>
>> I want to setup varnish as an loadbalancer for 4-5 Downloadserver.
>>
>> The best way to loadbalance with Failover is Roundrobin.
>>
>>  
>>
>>  
>>
>> backend img4 {
>>
>>   .host = "img4.test.com";
>>
>>   .probe = {
>>
>>                 .url = "/";
>>
>>                 .interval = 5s;
>>
>>                 .timeout = 1 s;
>>
>>                 .window = 5;
>>
>>                 .threshold = 3;
>>
>>   }
>>
>> }
>>
>>  
>>
>> backend img5 {
>>
>>   .host = "img5.test.com ";
>>
>>   .probe = {
>>
>>                 .url = "/";
>>
>>                 .interval = 5s;
>>
>>                 .timeout = 1 s;
>>
>>                 .window = 5;
>>
>>                 .threshold = 3;
>>
>>   }
>>
>> }
>>
>>  
>>
>>  
>>
>> backend img6 {
>>
>>   .host = "img6.test.com ";
>>
>>   .probe = {
>>
>>                 .url = "/";
>>
>>                 .interval = 5s;
>>
>>                 .timeout = 1 s;
>>
>>                 .window = 5;
>>
>>                 .threshold = 3;
>>
>>   }
>>
>> }
>>
>>  
>>
>> backend img7 {
>>
>>   .host = "img7.test.com ";
>>
>>   .probe = {
>>
>>                 .url = "/";
>>
>>                 .interval = 5s;
>>
>>                 .timeout = 1 s;
>>
>>                 .window = 5;
>>
>>                 .threshold = 3;
>>
>>   }
>>
>> }
>>
>>  
>>
>> director baz round-robin {
>>
>>         {
>>
>>                 .backend = img4;
>>
>>         }
>>
>>         {
>>
>>                 .backend = img5;
>>
>>         }
>>
>>          {
>>
>>                 .backend = img6;
>>
>>         }
>>
>>          {
>>
>>                 .backend = img7;
>>
>>         }
>>
>>        
>>
>> }
>>
>>  
>>
>> sub vcl_recv {
>>
>>   set obj.http.Location = baz;
>>
>>   set obj.status = 301;
>>
>>   return(deliver);
>>
>> }
>>
>>  
>>
>> I try to set other variables but it try to start with this gives an error.
>>
>>  
>>
>>
>> Has anybody an idea how it can works?
>>
>>  
>>
>> Thanks Carsten
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> varnish-misc mailing list
>> varnish-misc at varnish-cache.org
>> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>>     
>
>
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>
>
>   






More information about the varnish-misc mailing list