Varnish 3 - choose backend based on header field.

Gianni Carabelli gc at ants.eu
Fri Jan 11 11:00:50 CET 2013


On 01/11/2013 10:16 AM, Rafał Radecki wrote:
> Hi all.
> 
> I currently use varnish 3 in my environment. I use client director
> with two backends. I use set client.identity = client.ip to connect
> client session with backend.
> I would like to have the possibility to choose specific backend (first
> or second) based on the presence of a header in http request. If my
> request would have a header X-AppServer = app1 varnish should forward
> the request to the first application server if X-AppServer = app2 to
> the second and if there would be no such header it should use default
> client director. Is it possible in varnish 3?
> 
> Best regards,
> Rafal.
> 

in vcl_recv Something like:


if (req.http.header ~ "X-AppServer = app1") {
	 set req.backend = myBackend1
}

Have a look here:
https://www.varnish-cache.org/docs/3.0/reference/vcl.html#variables


Bye
JohnnyRun



More information about the varnish-misc mailing list