How to mark which backend server is used

There are use cases where you need to know which backend server is used, so use specific header to send target server name to backend.

HAProxy version.

$ sudo haproxy -v
HA-Proxy version 1.8.19-1 2019/02/12
Copyright 2000-2019 Willy Tarreau 

Define X-BACKEND-SERVER header using http-send-name-header statement.

X-BACKEND-SERVER header will be used to send target server name.
backend backend-local-production
  http-send-name-header X-BACKEND-SERVER

  server production-a 127.0.0.1:81
  server production-b 127.0.0.1:82

Sample frontend and backend configuration using this solution.

frontend web-frontend
  bind 192.168.50.190:80
  #bind :443 ssl crt /etc/ssl/cert/  

  mode http

  acl is-production hdr_dom(host) -i www.example.org

  use_backend backend-local-production if is-production
  
  default_backend backend-no-match

backend backend-local-production
  http-send-name-header X-BACKEND-SERVER
  server production-a 127.0.0.1:81
  server production-b 127.0.0.1:82

backend backend-no-match
  http-request deny deny_status 400

HAProxy will set X-BACKEND-SERVER: production-a or X-BACKEND-SERVER: production-b header depending on the used server.

References

HAProxy documentation - http-send-name-header