Health checking is the method to check service availability on a server. It is one of the most important features of a load balancer. How could we balance traffic amongst servers if we don’t know if the service is alive???
HAProxy & HTTP Check
HAProxy can probe HTTP applications using the httpchk option. This option can be customized using the http-check expect directive to match different status codes or content. That said, a single http-check expect rule can match. So we can’t match a status code and the presence of a string on the page, for example.
Make HAProxy Match Multiple Conditions for HTTP Health Checking
The solution is to use the raw tcp-check and write a health check script sequence matching all the conditions.
For example, you want to ensure the server’s response has:
HTTP status code is 200
absence of keyword Error
1. backend myapp
3. option tcp-check
4. tcp-check send GET /my/check/url HTTP/1.1rn
5. tcp-check send Host: myhostrn
6. tcp-check send Connection: closern
7. tcp-check send rn
8. tcp-check expect string HTTP/1.1 200 OK
9. tcp-check expect ! string Error
Related PagesSubscribe to our blog. Get the latest release updates, tutorials, and deep-dives from HAProxy experts.