Search code examples
sslhttpsload-balancingwildflyhaproxy

HAProxy health check in tcp mode on https 404 status code


I have two servers each running one Wildfly application server with one service available via https. The service is taking care of the https encryption. In front of the two servers I have an HAProxy as a load balancer in tcp mode to pass the ssl traffic through to the two services.

The HAProxy health check only checks if the server is online, not the service. If the service is not running Wildfly returns:

<html><head><title>Error</title></head><body>404 - Not Found</body></html>

which HAProxy interprets as healthy.

HAProxy config:

global  
    maxconn 2000

defaults
    log     global
    mode    http
    option  dontlognull
    retries 3
    option redispatch
    timeout connect  5000
    timeout client  10000
    timeout server  10000

listen backend
    bind *:8443
    mode tcp
    balance roundrobin
    option httpclose
    server backend1 wildfly:8443 check
    server backend2 xxx.xxx.xxx.xxx:8443 check

How can I make HAProxy understand that 404 - Not Found is not healthy.


Solution

  • Two lines did the trick:

    1. option httpchk /server
      • httpchk tells HAProxy to send an http request and check the response status
      • /server specifies the URI / Subdomain of my service
    2. server backend1 wildfly:8443 check check-ssl verify none
      • check-ssl tells HAProxy to check via https instead of http
      • verify none tells HAProxy to trust the ssl certificate of the service (alternativly you can specify a .pem file)

    Full HAProxy config:

    global  
        maxconn 2000
    
    defaults
        log     global
        mode    http
        option  dontlognull
        retries 3
        option redispatch
        timeout connect  5000
        timeout client  10000
        timeout server  10000
    
    listen backend
        bind *:8443
        mode tcp
        balance roundrobin
        option httpchk /server
        server backend1 xxx.xxx.xxx.xxx:8443 check check-ssl verify none
        server backend2 xxx.xxx.xxx.xxx:8443 check check-ssl verify none