global
maxconn 65535 #并发最大连接数量
stats socket /var/run/haproxy.stat mode 600 level admin
log 127.0.0.1 local0
uid 99 #用户 必须是本机查看显示的id
gid 99 #组
chroot /var/empty
daemon #后台运行
defaults
mode http #默认使用 http 的 7 层模式 tcp: 4 层
log global
option httplog #http 日志格式
option dontlognull #禁用空链接日志
monitor-uri /monitoruri
maxconn 8000
timeout client 300s
retries 2
option redispatch
timeout connect 300s
timeout server 300s
stats uri /admin/stats #haproxy 监控页面
# The public 'www' address in the DMZ
frontend public
bind 172.25.27.1:8001 name clear
#use_backend static if { hdr_beg(host) -i img }
#use_backend static if { path_beg /img /css }
default_backend dynamic
# The static backend backend for 'Host: img', /img and /css.
backend dynamic
option forwardfor
mode http
cookie SERVERID insert indirect nocache #基于cookie做负载均衡
server web1 127.0.0.1:10080 cookie web1 check inter 1500 rise 3 fall 3 weight 1
server web2 127.0.0.2:10080 cookie web2 check inter 1500 rise 3 fall 3 weight 1