1
votes

I'm trying to make http (layer 7) checks to monitor backend state in HAProxy load balancer. I have 3 backends configured, each having it's own name. Current configuration looks like this:

backend apiservers
  balance                 leastconn
  mode                    http
  option                  httpchk GET /healthz HTTP/1.0\r\nAuthorization:\ Bearer\ SOME_TOKEN_HERE
  http-check              disable-on-404
  http-check              expect rstring ^ok
  server                  core1 core1.cloud:443 ssl check
  server                  core2 core2.cloud:443 ssl check
  server                  core3 core3.cloud:443 ssl check

The problem is I can't switch to HTTP/1.1 because I wasn't able to find a way to pass a real Host header with httpchk requests. Using some random dummy Host string may cause problems in the feature, so I need to pass the corresponding backend hostname to the Host header. Options like http-request add-header Host %[src] and http-send-name-header Host in the backend section seem not affect httpchk mechanism. Any ideas?

1

1 Answers

2
votes

Updated thanks to borellini.

Per the haproxy docs you can configure the header in the httpchk line. The example from the docs is:

# check HTTP and HTTPs services on a server.
# first open port 80 thanks to server line port directive, then
# tcp-check opens port 443, ciphered and run a request on it:
option httpchk

http-check connect
http-check send meth GET uri / ver HTTP/1.1 hdr host haproxy.1wt.eu
http-check expect status 200-399
http-check connect port 443 ssl sni haproxy.1wt.eu
http-check send meth GET uri / ver HTTP/1.1 hdr host haproxy.1wt.eu
http-check expect status 200-399

server www 10.0.0.1 check port 80

You should then be able to replace the host value with your variable and have it sent.