Varnish 3 - choose backend based on header field.

Mad Indian themadindian at
Sun Jan 20 16:54:15 CET 2013

You could try with two backends named app1 and app2 and app_dir as the default director

if (req.http.X-AppServer == "app1") {
                set req.backend = app1;
        } else if (req.http.X-AppServer == "app2") {
                set req.backend = app2;
        } else {
                set req.backend = app_dir;

 From: Rafał Radecki <radecki.rafal at>
To: varnish-misc at 
Sent: Friday, January 11, 2013 4:16 AM
Subject: Varnish 3 - choose backend based on header field.
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,

varnish-misc mailing list
varnish-misc at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the varnish-misc mailing list