HAProxy 基于URL请求的负载均衡例子
网络环境
HAProxy服务器: 192.168.1.90
WEB1 : 192.168.1.103
WEB2 : 192.168.1.105
Domain: test.com
The below example includes ACL for url_beg. url_beg matches the string used in url submitted. Using the url all requests starting with /blog ( test.net/blog ) will redirect to WEB2 ( 192.168.1.105 ) Server. All other requests will redirect to one of two server ( WEB1, WEB2 ), depending on load balancing algorithm used.
Here is a quick example of uses url_beg ACL:
global
log 127.0.0.1 local0 notice
maxconn 50000
daemon
defaults
log global
mode http
option httplog
option dontlognull
contimeout 120000
clitimeout 120000
srvtimeout 120000
option forwardfor
option http-server-close
# Configuration for HTTP site
frontend http-in
bind 192.168.1.90:80
acl is_blog url_beg /blog
use_backend tecadmin_blog if is_blog
default_backend tecadmin_website
backend tecadmin_blog
mode http
balance roundrobin # Load Balancing algorithm
option httpchk
option forwardfor
server WEB2 192.168.1.105:80 weight 1 maxconn 512 check
backend tecadmin_website
mode http
balance roundrobin # Load Balancing algorithm
option httpchk
option forwardfor
server WEB1 192.168.1.103:80 weight 1 maxconn 512 check
server WEB2 192.168.1.105:80 weight 1 maxconn 512 check