timeout queue 1m #一个请求在队列里的超时时长
timeout connect 10s #设定在haproxy转发至后端upstream server时等待的超时时长
timeout client 1m #client的一次非活动状态的超时时长
timeout server 1m #等待服务器端的非活动的超时时长
timeout http-keep-alive 10s #持久连接超时时长
timeout check 10s #检查请求连接的超时时长
maxconn 3000 #最大连接数
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend webserver *:80
acl url_static path_beg -i /static /images /javascript /stylesheets #匹配path以/static,/images开始的,且不区分大小写
acl url_static path_end -i .jpg .gif .png .css .js .html
acl url_static hdr_beg(host) -i img. video. download. ftp. imgs. image.
acl url_dynamic path_end .php .jsp
use_backend static if url_static #满足名为url_static这条acl规则,则将请求转发至后端名为static的real server组中去
use_backend dynamic if url_dynamic
default_backend static #如果上面所有acl规则都不满足,将请求转发到static组中
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static #定义后端real server组,组名为static
balance roundrobin #支持动态权重修改,支持慢启动
server static_1 172.16.0.100:80 check inter 3000 fall 3 rise 1 maxconn 30000
server static_2 172.16.0.101:80 check inter 3000 fall 3 rise 1 maxconn 30000
server static_Error 172.16.0.1:8080 backup check #当此组中的所有server全部不能提供服务,才将请求调度至此server上
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend dynamic
cookie cookie_name insert nocache #使用cookie实现session绑定,且不记录缓存
balance roundrobin
server dynamic1 172.16.0.200:80 check inter 3000 fall 3 rise 1 maxconn 1000 cookie dynamic1
server dynamic2 172.16.0.201:80 check inter 3000 fall 3 rise 1 maxconn 1000 cookie dynamic2 #定义dynamic组中的server,将此server命名为dynamic2,每隔3000ms检测一个健康状态,如果检测3次都失败,将此server剔除。在离线的状态下,只要检测1次成功,就让其上线,此server支持最大的并发连接数为1000,cookie的值为dynamic2