How to get name of server that has served request in fronted section?

I need to add server name in response HTTP headers X-Servedby. Is there any way to replace [server] with name of server that has served request?

frontend front x.x.x.x:80
  default_backend balancing
  rspadd X-Servedby:\ [server] #I need to replace [server]

backend balancing
  server srv1 x.x.x.x:80 check
  server srv2 x.x.x.x:80 check

To achieve this, change the frontend stanza to the following:

frontend front x.x.x.x:80
    default_backend balancing
    acl srv1 srv_id 1
    acl srv2 srv_id 2
    rspadd X-Servedby:\ srv1 if srv1
    rspadd X-Servedby:\ srv2 if srv2

However, a better scaling alternative would be to use cookie in the backend stanza:

backend balancing
    cookie SRVNAME insert
    server srv1 x.x.x.x:80 cookie srv1 check
    server srv2 x.x.x.x:80 cookie srv2 check

Hope this helps!


We should use srv_id which provides id value defined for server

frontend front x.x.x.x:80

  acl serve_us1 url_beg /west
  acl serve_us2 url_beg /east

  #defining acl for srv_id
  acl served_by_us1 srv_id 1  #look at srv_id
  acl served_by_us2 srv_id 2  #look at srv_id

  use_backend us1 if serve_us1
  use_backend us2 if serve_us2 
  default_backend balancing

  rspadd X-ServedBy:\ us1 if served_by_us1
  rspadd X-ServedBy:\ us2 if served_by_us2

backend us1
  server srv1 1.1.1.1:80 check id 1 #look at id

backend us2
  server srv2 2.2.2.2:80 check id 2 #look at id

backend balancing
  server srv1 1.1.1.1:80 check id 1 #look at id
  server srv2 2.2.2.2:80 check id 2 #look at id