# 全局配置,日志,运行安装路径,
global
log 127.0.0.1 local3 info
maxconn 50000
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
stats socket /var/lib/haproxy/haproxy.sock mode 660 level admin
#stats timeout 30s
user haproxy
group haproxy
daemon
# 默认配置
defaults
log global
mode http
# 记录http日志,不记录空连接日志,用X-Forwarded-For向后端服务器传递客户端来源IP,减少对后端服务器的连接数
option httplog
option dontlognull
option forwardfor
option http-keep-alive
timeout connect 5000ms
timeout client 10000ms
timeout server 10000ms
timeout check 5000ms
# 状态监控页面
frontend http_frontend
# 状态页面开启,绑定地址,每5s自动刷新,隐藏版本,状态访问页面,认证账号,密码,条件满足进入管理界面
stats enable
bind 0.0.0.0:80
stats refresh 100s
stats hide-version
stats uri /haproxy-status
stats realm "HAProxy/ static"
stats auth admin:admin123
stats admin if TRUE
# 允许的网段,允许,拒绝
#acl allow src 192.168.12.0/24
#tcp-request content accept if allow
#tcp-request content reject
# haproxy日志记录内容
capture request header Host len 40
capture request header Referer len 60
capture response header Server len 40
capture response header Content-Length len 20
capture response header Cache-Control len 20
capture response header Via len 30
capture response header Location len 20
# 创建一个acl名字为iapp
acl iapp hdr_beg(host) iapp.pinhui001.com
use_backend iapp_pinhui001_com if iapp
acl icontent hdr_beg(host) icontent.pinhui001.com
use_backend icontent_pinhui001_com if icontent
acl imember hdr_beg(host) imember.pinhui001.com
use_backend imember_pinhui001_com if imember
acl itopic hdr_beg(host) itopic.pinhui001.com
use_backend itopic_pinhui001_com if itopic
acl itrade hdr_beg(host) itrade.pinhui001.com
use_backend itrade_pinhui001_com if itrade
acl iverify hdr_beg(host) iverify.pinhui001.com
use_backend iverify_pinhui001_com if iverify
acl iware hdr_beg(host) iware.pinhui001.com
use_backend iware_pinhui001_com if iware
acl ihelpapi hdr_beg(host) ihelpapi.pinhui001.com
use_backend ihelpapi_pinhui001_com if ihelpapi
# https acl
acl ipassport hdr_beg(host) ipassport.pinhui001.com
use_backend ipassport_pinhui001_com if ipassport
acl ipay hdr_beg(host) ipay.pinhui001.com
use_backend ipay_pinhui001_com if ipay
acl isend hdr_beg(host) isend.pinhui001.com
use_backend isend_pinhui001_com if isend
# log acl
acl ibusines hdr_beg(host) ibusines.pinhui001.com
use_backend ibusines_pinhui001_com if ibusines
acl iexception hdr_beg(host) iexception.pinhui001.com
use_backend iexception_pinhui001_com if iexception
acl ioperation hdr_beg(host) ioperation.pinhui001.com
use_backend ioperation_pinhui001_com if ioperation
acl itracker hdr_beg(host) itracker.pinhui001.com
use_backend itracker_pinhui001_com if itracker
# ====================================http=======================================
backend iapp_pinhui001_com
mode http
# 轮询,源地址负载调度算法,cookie
balance roundrobin
#balance source
cookie appsession insert indirect preserve
timeout http-request 3s
timeout http-keep-alive 3s
timeout connect 1s
timeout server 10s
timeout check 500ms
# 后端服务器故障时,重新分发请求
option redispatch
option http-keep-alive
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:10.1.8.13:8802
#http-check expect string ok
#retries 2
server web01 10.1.8.12:8801 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web02 10.1.8.13:8801 check cookie s2 inter 2000 rise 3 fall 3 weight 1
backend icontent_pinhui001_com
mode http
balance roundrobin
#balance source
cookie appsession insert indirect preserve
option http-keep-alive
option redispatch
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:icontent.pinhui001.com
server web01 10.1.8.12:8802 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web02 10.1.8.13:8802 check cookie s2 inter 2000 rise 3 fall 3 weight 1
backend imember_pinhui001_com
mode http
balance roundrobin
#balance source
cookie appsession insert indirect preserve
option http-keep-alive
option redispatch
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:imember.pinhui001.com
server web01 10.1.8.12:8803 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web02 10.1.8.13:8803 check cookie s2 inter 2000 rise 3 fall 3 weight 1
backend itopic_pinhui001_com
mode http
balance roundrobin
#balance source
cookie appsession insert indirect preserve
option http-keep-alive
option redispatch
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:itopic.pinhui001.com
server web01 10.1.8.12:8805 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web02 10.1.8.13:8805 check cookie s2 inter 2000 rise 3 fall 3 weight 1
backend itrade_pinhui001_com
mode http
balance roundrobin
#balance source
cookie appsession insert indirect preserve
option redispatch
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:itrade.pinhui001.com
server web01 10.1.8.12:8806 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web02 10.1.8.13:8806 check cookie s2 inter 2000 rise 3 fall 3 weight 1
backend iverify_pinhui001_com
mode http
balance roundrobin
#balance source
cookie appsession insert indirect preserve
option http-keep-alive
option redispatch
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:iverifiy.pinhui001.com
server web01 10.1.8.12:8807 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web02 10.1.8.13:8807 check cookie s2 inter 2000 rise 3 fall 3 weight 1
backend iware_pinhui001_com
mode http
balance roundrobin
#balance source
cookie appsession insert indirect preserve
option http-keep-alive
option redispatch
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:iware.pinhui001.com
server web01 10.1.8.12:8808 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web02 10.1.8.13:8808 check cookie s2 inter 2000 rise 3 fall 3 weight 1
backend ihelpapi_pinhui001_com
mode http
balance roundrobin
#balance source
cookie appsession insert indirect preserve
option http-keep-alive
option redispatch
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:ihelpapi.pinhui001.com
server web01 10.1.8.12:8809 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web02 10.1.8.13:8809 check cookie s2 inter 2000 rise 3 fall 3 weight 1
# ====================================https======================================================
backend ipassport_pinhui001_com
mode http
balance roundrobin
#balance source
cookie appsession insert indirect preserve
option http-keep-alive
option redispatch
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:ipassport.pinhui001.com
server web03 10.1.8.14:8801 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web04 10.1.8.15:8801 check cookie s2 inter 2000 rise 3 fall 3 weight 1
backend ipay_pinhui001_com
mode http
balance roundrobin
#balance source
cookie appsession insert indirect preserve
option http-keep-alive
option redispatch
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:ipay.pinhui001.com
server web03 10.1.8.14:8802 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web04 10.1.8.15:8802 check cookie s2 inter 2000 rise 3 fall 3 weight 1
backend isend_pinhui001_com
mode http
balance roundrobin
#balance source
cookie appsession insert indirect preserve
option http-keep-alive
option redispatch
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:isend.pinhui001.com
server web03 10.1.8.14:8803 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web04 10.1.8.15:8803 check cookie s2 inter 2000 rise 3 fall 3 weight 1
# ========================================logs=======================================================
backend ibusines_pinhui001_com
mode http
balance roundrobin
#balance source
cookie appsession insert indirect preserve
option http-keep-alive
option redispatch
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:ipassport.pinhui001.com
server web01 10.1.8.23:8801 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web02 10.1.8.24:8801 check cookie s2 inter 2000 rise 3 fall 3 weight 1
backend iexception_pinhui001_com
mode http
balance roundrobin
#balance source
cookie appsession insert indirect preserve
option http-keep-alive
option redispatch
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:ipassport.pinhui001.com
server web01 10.1.8.23:8802 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web02 10.1.8.24:8802 check cookie s2 inter 2000 rise 3 fall 3 weight 1
backend ioperation_pinhui001_com
mode http
balance roundrobin
#balance source
cookie appsession insert indirect preserve
option http-keep-alive
option redispatch
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:ipassport.pinhui001.com
server web01 10.1.8.23:8803 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web02 10.1.8.24:8803 check cookie s2 inter 2000 rise 3 fall 3 weight 1
backend itracker_pinhui001_com
mode http
balance roundrobin
#balance source
cookie appsession insert indirect preserve
option http-keep-alive
option redispatch
option forwardfor header X-REAL-IP
#option httpchk GET /favicon.ico HTTP/1.1\r\nHost:ipassport.pinhui001.com
server web01 10.1.8.23:8804 check cookie s1 inter 2000 rise 3 fall 3 weight 1
server web02 10.1.8.24:8804 check cookie s2 inter 2000 rise 3 fall 3 weight 1
# =======================================================================================================