Centos7.1 1503最小化安装,nginx和haproxy通过yum安装,关闭防火墙,清空iptables

haproxy主机ip:192.168.70.161

后端nginx主机ip:192.168.70.158,192.168.70.159

一、配置haproxy,只保留到defaults,下面的修改为如下

frontend  main *:80
        acl test2 hdr_beg(host) -i node2.linuxu.me        //acl设定匹配请求的url
        acl test3 hdr_beg(host) -i node3.linuxu.me
    use_backend node2          if test2
        use_backend node3       if test3
        default_backend             node2
backend node2                                                              //设置两台后端nginx服务器
    balance     roundrobin
    server      node2 192.168.70.159:80 check
backend node3
    balance     roundrobin
    server  node3 192.168.70.158:80 check

二、分别在nginx原index.html添加h1字段以区别,注意是在head里分别添加

node2
<h1>node2.linuxu.me</h1>
node3
<h1>node3.linuxu.me</h1>

三、添加host文件并访问测试

haproxyQQ截图20150504104135.png

haproxyQQ截图20150504104341.png

haproxyQQ截图20150504104355.png