wushi 发表于 2015-11-20 11:17:04

haproxy 页面重定向(域名跳转)

<pre name=&quot;code&quot; class=&quot;sql&quot;>redirect location <to> <option> [{if | unless} <condition>]
redirect prefix   <to> <option> [{if | unless} <condition>] 重定向,相当于rewrite


###########acl 开始了############
acl bbs       hdr_reg(host) -i ^(bbs.test.com|forum.test.com)#使用正则匹配
acl bbs_pathpath_beg -i /bbs                #url 目录
acl youxi   path_beg -i /youxi               
acl static    path_end -i .html .css .js      #url 结尾文件
acl php       path_end -i .php
acl jsp       path_end -i .jsp .do
use_backend bbs_pool if bbs or bbs_path       #注意 &quot;or&quot;
use_backend youxi_pool if youxi
use_backend static_pool if static
use_backend php_pool if php
use_backend jsp_pool if jsp
default_backend www.test.com               
###########acl 结束了############

#当满足host_zjcap.cn的策略,跳转(重定向)到http://www.zjcap.cn
acl host_zjcap.cnhdr_beg(host)-i (zjcap.cn|zhongjunziben.com)
redirect prefix   http://www.zjcap.cn if host_zjcap.cn

分类: LINUX
在邮件列表看到有个人问haproxy能否在接到一个请求时选择一个后端服务器,然后301重定向url 。
主要原因是他有5个1G的出口,这样就能充分利用其带宽。
测试了一下是可以的
frontend free
bind *:80
default_backend lvs2
backend lvs2
mode http
option forwardfor header ORIG_CLIENT_IP
server free174 10.253.3.16:8081 redir http://free71-174-st.inner.net:8081 weight 10 rise 3 fall 5 check inter 2000
server free173 10.253.3.15:8081 redir http://free71-173-st.inner.net:8081 weight 10 rise 3 fall 5 check inter 2000
当输入负载均衡机器的域名后,url会直接变成http://free71-17(3|4)-st.inner.net:8081.

acl monitor hdr_beg(host) -i monitor.test.com    #定义ACL名称(monitor),对应的请求的主机头是monitor.test.com

acl bbs       hdr_reg(host) -i ^(bbs.test.com|forum.test.com)#使用正则匹配

acl host_zjcap.cnhdr_beg(host)-i zjcap.cn
acl host_zjzc.cnhdr_beg(host)-i zhongjunziben.com
redirect prefix   http://www.zjcap.cn if host_zjcap.cn
redirect prefix   http://www.zjcap.cn if host_zjzc.cn

frontend localhost
bind *:80
bind *:443 ssl crt /etc/ssl/xip.io/xip.io.pem
redirect scheme https if !{ ssl_fc }
mode http
default_backend nodes
上面,我们添加了 redirect 导向,如果连接不是通过SSL连接的,它将 http 重定向到 https

acl host_zjcap.cnhdr_beg(host)-i zjcap.cn
acl host_zjzb.cnhdr_beg(host)-i zhongjunziben.com
acl www_zjzb.cnhdr_beg(host)-i www.zhongjunziben.com
acl host_zjzc.cnhdr_beg(host)-i zhongjunzichan.com
acl www_zjzc.cnhdr_beg(host)-i www.zhongjunzichan.com
redirect prefix   http://www.zjcap.cn if host_zjcap.cn
redirect prefix   http://www.zjcap.cn if host_zjzb.cn
redirect prefix   http://www.zjcap.cn if www_zjzb.cn
redirect prefix   http://www.zjcap.cn if host_zjzc.cn
redirect prefix   http://www.zjcap.cn if www_zjzc.cn
访问 zhongjunziben.com 和 zhongjunzichan.com 跳转到http://www.zjcap.cn
页: [1]
查看完整版本: haproxy 页面重定向(域名跳转)