haproxy配置例子

global
chroot /application/haproxy-1.4.22/var/chroot
daemon
group haproxy
user haproxy
#log 127.0.0.1:514 local0 info
log 127.0.0.1:514 local0 warning
pidfile /application/haproxy-1.4.22/var/run/haproxy.pid
maxconn 20000
spread-checks 3
nbproc 8
defaults
log global
mode http
retries 3
option redispatch
contimeout 5000
clitimeout 50000
srvtimeout 50000
stats enable
stats hide-version
stats uri /admin?stats
stats auth proxy:123456
option httpclose

frontend webserver
bind 10.0.0.17:80
#1)实现301跳转
#需求1.etiantian.org -->nginx.etiantian.org (301)
#(short_dom为自定义名称 hdr函数包含Host -i(不区分大小写) 匹配etiantian.org )
acl short_dom hdr(Host) -i etiantian.org
#prefix 前缀跳转 保证访问http://etiantian.org/a.html能够跳转到http://nginx.etiantian.org/a.html
redirect prefix http://nginx.etiantian.org code 301 if short_dom

    acl oldboy_static path_beg /nginx/
    acl oldboy_php path_beg /php/
    acl oldboy_java path_beg /resin/
    acl oldboy_pic  path_end  .gif .png .jpg .css .js

    acl iphone_users hdr_sub(user-agent)  -i iphone
    redirect prefix http://3g-iphone.etiantian.org if iphone_users

    acl android_users hdr_sub(user-agent)  -i android
    redirect prefix http://3g-android.etiantian.org/ if android_users

    use_backend nginxpools if oldboy_static or oldboy_pic
    use_backend phppools if oldboy_php
    use_backend javapools if oldboy_java

    default_backend nginxpools

nginx static contents

backend nginxpools
balance roundrobin
server oldboy_8000 10.0.0.8:8000

php contents

backend phppools
balance roundrobin
server oldboy_9000 10.0.0.8:9000

java contents

backend javapools
balance roundrobin
server oldboy_10000 10.0.0.8:10000

你可能感兴趣的:(haproxy配置例子)