# How to add header to per server backend

**URL:** <https://discourse.haproxy.org/t/how-to-add-header-to-per-server-backend/252>\
**Category:** Help!\
**Created:** [May 5, 2016, 4:58am UTC](https://discourse.haproxy.org/t/how-to-add-header-to-per-server-backend/252 "2016-05-05T04:58:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kotarusv](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@kotarusv](https://discourse.haproxy.org/u/kotarusv)\
**Post date:** [May 5, 2016, 4:58am UTC](https://discourse.haproxy.org/t/how-to-add-header-to-per-server-backend/252/1 "2016-05-05T04:58:31Z")

</div>

Hi

i have a unique requirement. We have to add a custom header for every backend server definition. This header will be analysed by downstream SSO agent and forward to appropriate IP address specified in header after authentication. This custom header contain iP address of router . SSO servers running from different servers. RP server simple send all incoming traffic to SSO server as shown below example.

SSO server doesn’t have too much intelligent except look into header send by RP server and forward to appropriate IP address after authentication was done.

request flow:

url --\> HAProxy RP server --\> SSO server --\> DC specific router --\> application

RP server simply send traffic to SSO server for all traffic. SSO server does authentication and look for X-SSO hader. based on the IP address of this header, it will forward to that IP address.

I want to a rule something like below

acl is\_sales4 hdr(host) -i [sales-sso-mvdc.example.com](http://sales-sso-mvdc.example.com)  
use\_backend sales4\_backend if is\_sales4

backend sales4\_backend  
cookie SERVERID insert indirect nocache  
balance roundrobin  
server server4 sso\_server1:3000 check cookie sales-sso-dc1 http-request set-header X-SSO 10.42.137.158  
server server5 sso\_server2:3000 check cookie sales-sso-dc2 http-request set-header X-SSO 10.42.137.158

I knew it is not possible. i checked HAProxy documentation. server options doesn’t support per server http-request header setting. We can set up only at backend definition but not per server basis. I can’t use conditional http-request also since it doesn’t have any such unique criteria.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![kotarusv](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@kotarusv](https://discourse.haproxy.org/u/kotarusv)\
**Post date:** [May 5, 2016, 6:52pm UTC](https://discourse.haproxy.org/t/how-to-add-header-to-per-server-backend/252/2 "2016-05-05T18:52:15Z")

</div>

Hi

Any ideas or suggestions for above problem?

Srinivas Kotaru

---

<div class="post-metadata">

**Author:** ![willy](https://avatars.discourse-cdn.com/v4/letter/w/c2a13f/32.png) [@willy](https://discourse.haproxy.org/u/willy)\
**Post date:** [May 9, 2016, 5:47am UTC](https://discourse.haproxy.org/t/how-to-add-header-to-per-server-backend/252/3 "2016-05-09T05:47:24Z")

</div>

You should check the directive “http-send-name-header”. It allows you to insert the server name into a given header field before passing the request to the server. It was designed exactly for this purpose.

---

<div class="post-metadata">

**Author:** ![kotarusv](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@kotarusv](https://discourse.haproxy.org/u/kotarusv)\
**Post date:** [May 10, 2016, 7:27am UTC](https://discourse.haproxy.org/t/how-to-add-header-to-per-server-backend/252/4 "2016-05-10T07:27:45Z")

</div>

Willy

Thank you very much. It is working. below is sample config

backend sales4\_backend  
cookie SERVERID insert indirect nocache  
option httpchk HEAD /pingpong.html HTTP/1.1\r\nHost:\ [sales-sso-multidc.example.com](http://sales-sso-multidc.example.com)  
http-check expect ! rstatus ^5  
http-send-name-header X-SSO  
balance roundrobin  
server 10.42.137.158 server1:3000 ssl verify none check cookie sales-sso-dc1 inter 2000 rise 2 fall 3  
server 10.42.136.152 server1:3000 ssl verify none check cookie sales-sso-dc2 inter 2000 rise 2 fall 3

now downstream SSO agent was able to see x-sso header with IP’s. These IP represent router where SSO agent has to forward after authentication. so far so good

am having issues at health probes. I still need to send this header and IP even for health probes also. By default health probes not honoring http-send-name-header . when health probes are send to downstream server ( SSO agent), it was unable to decide where to forward since x-sso and IP missing.

I used below approach but that also not working. I need help to verify whetehr it is possible to send header for probes

backend sales4\_backend  
cookie SERVERID insert indirect nocache  
option httpchk HEAD /internal-check  
http-check expect ! rstatus ^5  
http-send-name-header X-SSO  
balance roundrobin  
server 10.42.137.158 server13000 ssl verify none check cookie sales-sso-dc1 inter 2000 addr 127.0.0.1 port 49170 rise 2 fall 3  
server 10.42.136.152 server1:3000 ssl verify none check cookie sales-sso-dc2 inter 2000 addr 127.0.0.1 port 49171 rise 2 fall 3

listen monitor-mdm\_prod\_head\_1  
bind 127.0.0.1:49170  
monitor-uri /internal-check  
monitor fail if { nbsrv(monitor-mdm\_prod\_head\_1) eq 0 }  
option httpchk HEAD /pingpong.html HTTP/1.1\r\nHost:\ [sales-sso-multidc.example.com](http://sales-sso-multidc.example.com)\r\nX-SSO:\ 10.42.137.158  
http-check expect ! rstatus ^5  
server mdm\_prod\_head\_1 server1:3000

listen monitor-mdm\_prod\_head\_2  
bind 127.0.0.1:49171  
monitor-uri /internal-check  
monitor fail if { nbsrv(monitor-mdm\_prod\_head\_1) eq 0 }  
option httpchk HEAD /pingpong.html HTTP/1.1\r\nHost:\ [sales-sso-multidc.example.com](http://sales-sso-multidc.example.com)\r\nX-SSO:\ 10.42.137.152  
http-check expect ! rstatus ^5  
server mdm\_prod\_head\_1 server1:3000

am getting below error in logs

May 10 01:47:22 skotaru-vm1 haproxy-80[8045]: Health check for server sales4\_backend/10.42.137.158 failed, reason: Layer7 invalid response, info: “\<3C\>!DOCTYPE html PUBLIC \<22\>-//W3C//DTD XHTML 1.0 Transitional//EN\<22\> \<22\>[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)\<22\>\<3E\>”, check duration: 0ms, status: 2/3 UP.

I tried multiple combinations with option httpchk with

option httpchk HEAD /pingpong.html HTTP/1.1\r\nHost:\ [sales-sso-multidc.example.com](http://sales-sso-multidc.example.com)\r\nX-SSO:\ 10.42.137.152\r\n\r\n

(or)  
option httpchk HEAD /pingpong.html HTTP/1.1\r\nHost:\ [sales-sso-multidc.example.com](http://sales-sso-multidc.example.com)\r\nX-SSO:\ 10.42.137.152\r\n

Questions/

1. is it possible to send another header along with Host: with helath probes?
2. if Yes what is the syntax.

Thanks you very much in advance.

Srinivas Kotaru
