Sunday, January 23, 2011

How do I get varnish to return in the http response header from which backend it took the response?

I have three servers in the backend, with a round robin director.

I would like varnish to write a X-Server-By header with the name or ip of the server from which the response was fetched, how can this be done?

  • The following is not tested, but might get you started:

    sub vcl_deliver {
        set resp.http.X-Served-By = server.hostname;
        deliver;
    }
    
  • sub vcl_fetch {
        set obj.http.X-Backend = req.backend;
    }
    

    Tested on 2.0.6 in my (non round robin) setup. It should give you something to go on.

    From rossnz

0 comments:

Post a Comment