http-request: 7層過濾
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
nbproc 1
maxconn 8000
user haproxy
group haproxy
daemon
#stats socket /var/lib/haproxy/stats
defaults
mode tcp
log global
option tcplog
option dontlognull
#option http-server-close
#option forwardfor except 127.0.0.0/8
#option redispatch
retries 3
#timeout http-request 10s
#timeout queue 1m
timeout connect 10s
timeout client 15m
timeout server 15m
#timeout http-keep-alive 10s
timeout check 10s
maxconn 6000
listen admin_stats
bind 0.0.0.0:9188
mode http
log 127.0.0.1 local3 err
#HAProxy監控頁面統計自動刷新時間。
stats refresh 30s
#設置監控頁面URL路徑。 http://IP:9188/haproxy-status可查看
stats uri /haproxy
#統計頁面密碼框提示信息
stats realm welcome login\ Haproxy
#登錄統計頁面用戶和密碼
stats auth admin:123456
#隱藏HAProxy版本信息
stats hide-version
#設置TURE后可在監控頁面手工啟動關閉后端真實服務器
#stats admin if TRUE
#設置允許訪問的IP段
acl allow_host src 10.0.0.0/8
http-request allow if allow_host
#拒絕其他IP的http請求
http-request deny
frontend api1
bind *:80
mode tcp
log global
#設置允許訪問的IP段
acl allow_host src 10.0.0.0/8
tcp-request content accept if allow_host
#拒絕其他IP的http請求
tcp-request content reject
default_backend api1pool
backend api1pool
balance roundrobin
server api1 10.10.10.101:80 check inter 2000 rise 2 fall 3 maxconn 3000
server api2 10.10.10.102:80 check inter 2000 rise 2 fall 3 maxconn 3000