I have a server that host multiple sites but logically looks like sub directories. Example:
- http://XXX/Site1
- http://XXX/Site2
How do I configure HAProxy's health check to check each "sub site"?
Use multiple backends, each checking 1 site. Use ACLs to perform content switching, i.e. selecting the backend to route the request to based on some property of the HTTP request, in this case the URL path.
Example:
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
user haproxy
group haproxy
daemon
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
timeout connect 5000
timeout client 50000
timeout server 50000
frontend 1.2.3.4-80
bind 1.2.3.4:80
mode http
option http-server-close
option logasap
acl url_site1 url_beg /Site1
acl url_site2 url_beg /Site2
use_backend site1 if url_site1
use_backend site2 if url_site2
backend site1
mode http
balance roundrobin
option httpchk HEAD /Site1 HTTP/1.1\r\nHost:\ XXX
server srv1 1.1.1.1:80 check
server srv2 2.2.2.2:80 check
backend site2
mode http
balance roundrobin
option httpchk HEAD /Site2 HTTP/1.1\r\nHost:\ XXX
server srv1 1.1.1.1:80 check
server srv2 2.2.2.2:80 check
You can enable HTTP check in Haproxy to check HTTP Servers
https://code.google.com/p/haproxy-docs/wiki/httpchk
backend cluster1
mode http
balance roundrobin
option httplog
option httpclose #Disable keepalive
option forwardfor
option httpchk HEAD /check.txt HTTP/1.0
backend cluster2
mode http
balance roundrobin
option httplog
option httpclose #Disable keepalive
option forwardfor
option httpchk HEAD /check.txt HTTP/1.0
# Servers