HTTP Health Checks
An HTTP-layer health check sends an HTTP OPTIONS request to the server and expects to get a successful response. To enable it, add option httpchk
to the backend
section:
backend be_myapp
option httpchk
server srv1 192.168.1.5:80 check
Checks are sent using GET to the URL / by default.
You can change the HTTP method and URL by specifying them on the option httpchk
line. In the following example, checks are sent using GET to the URL /healthz:
backend be_myapp
option httpchk GET /healthz
server srv1 10.0.0.1:80 check
server srv2 10.0.0.2:80 check
If the response status code is in the 2xx or 3xx range, the server is healthy.
Customizing the HTTP check with the send directive
Another way to change the HTTP method and URL is by adding the http-check send
line and specifying the new values there. In the following example, checks are sent using GET to the URL /healthz:
backend be_myapp
option httpchk
http-check send meth HEAD uri /healthz ver HTTP/1.1 hdr Host test.local
server srv1 192.168.1.5:80 check
You can send POST requests, too:
backend be_myapp
option httpchk
http-check send meth POST uri /health hdr Content-Type "application/json;charset=UTF-8" hdr Host www.mwebsite.com body "{\"id\": 1, \"field\": \"value\"}"
server srv1 192.168.1.5:80 check
For the complete list of parameters that can be specified on the send
line, see http-check send.
Multiple HTTP endpoints
Additional power comes from the ability to query several endpoints during a single health check. In the following example, we make requests to two distinct services: one listening on port 8080 and the other on port 8081. We also use different URIs. If either endpoint fails to respond, the entire health check fails.
backend servers
option httpchk
http-check connect port 8080
http-check send meth HEAD uri /health
http-check connect port 8081
http-check send meth HEAD uri /up
server server1 127.0.0.1:80 check
Next up
Health Check Interval