基于URL的HAProxy负载均衡设置
例子包括ACL的url_beg。 url_beg提交URL中使用的字符串相匹配。
使用URL /blog(cnblog/api)所有请求重定向到WEB服务器的6200端口。所有其他请求将重定向到服务器的6100端口,根据负载均衡使用的算法。 下面是使用url_beg ACL的一个简单的例子:
global
#log /dev/log local6
log 192.168.1.110:51405 local7
maxconn 100000
uid 99
gid 99
daemon
stats socket /var/run/haproxy.stat mode 644
quiet
defaults
log global
mode http
option httplog
option dontlognull
option httpclose
option forceclose
option forwardfor
option redispatch
option allbackups
option http-server-close
option log-health-checks
retries 3
balance roundrobin
maxconn 20000
timeout connect 10000
timeout client 50000
timeout server 50000
timeout check 10000
listen haproxy-statistics
bind 0.0.0.0:11180
stats enable
stats admin if TRUE
stats refresh 30s
stats hide-version
stats uri /haproxy-status
stats realm Haproxy\ statistics
stats auth deed:6ddu7
listen haproxy-monitoring
bind 0.0.0.0:11190
mode health
monitor-net 192.168.1.0/24
no option forceclose
no option httpclose
no option http-server-close
frontend api.cnblog.cn:6200
bind *:6200
mode http
acl api.cnblog.cn url_beg /api
use_backend api.cnblog.cn if api.cnblog.cn
default_backend api_cnblog.cn
backend api.cnblog.cn
mode http
balance roundrobin
#cookie SERVERID insert indirect nocache
#option httpchk GET /alived.gif HTTP/1.1\r\nHost:\ api.cnblog.cn
server tomcat_10.211 192.168.1.211:6200 check inter 10000 rise 2 fall 3
server tomcat_10.212 192.168.1.212:6200 check inter 10000 rise 2 fall 3
backend api_cnblog.cn
mode http
balance roundrobin
#cookie SERVERID insert indirect nocache
#option httpchk GET /alived.gif HTTP/1.1\r\nHost:\ api.cnblog.cn
server tomcat_10.211 192.168.1.211:6100 check inter 10000 rise 2 fall 3
server tomcat_10.212 192.168.1.212:6100 check inter 10000 rise 2 fall 3
目录 返回
首页