apache 反向代理,负载均衡配置。

1.服务器http 服务Apache/2.2.15 (Unix)进行反向代理配置:

 

      1) 基于虚拟主机的反响代理配置

准备两个http服务:

[root@yun02 ~]# curl 192.168.154.129:8881/test
111111111111111

[root@yun02 ~]# curl 192.168.154.129:8882/test
22222222222 

如果是之前没有做过虚拟主机的配置,则在http.conf 尾部新增如下配置。分别为两个服务做代理转发。

如果是之前有虚拟主机配置,则在对应的端口主机中进行新增代理,如下红色字体
<VirtualHost *:80>
ServerName yun01
ServerAlias yun01
ProxyRequests off
<Proxy *>
    Order allow,deny
    Allow from all
</Proxy>
ProxyPass /p1 http://192.168.154.129:8882/
ProxyPassReverse /p1 http://192.168.154.129:8882/

ProxyPass /p2 http://192.168.154.129:8881/
ProxyPassReverse /p2 http://192.168.154.129:8881/


</VirtualHost>

重新load #

 检查语法: /usr/sbin/apachectl -t

生效:  /usr/sbin/apachectl graceful 或

 service httpd reload


#############测试#############

[root@yun02 ~]# curl yun01/p1/test
22222222222

[root@yun02 ~]# curl yun01/p2/test
111111111111111


     2) 负载均衡配置:在此处配置基于http的负载均衡

<Proxy balancer://mycluster>
BalancerMember http://192.168.154.129:8882/
BalancerMember http://192.168.154.129:8881/
</Proxy>



<VirtualHost *:80>
ServerName yun01
ServerAlias yun01
ProxyRequests off
<Proxy *>
    Order allow,deny
    Allow from all
</Proxy>
ProxyPass /p1 http://192.168.154.129:8882/
ProxyPassReverse /p1 http://192.168.154.129:8882/


ProxyPass /p2 http://192.168.154.129:8881/
ProxyPassReverse /p2 http://192.168.154.129:8881/


ProxyPass /p3 balancer://mycluster/
ProxyPassReverse /p3 balancer://mycluster/
</VirtualHost>

 

重新load #

 检查语法: /usr/sbin/apachectl -t

生效:  /usr/sbin/apachectl graceful 或

 service httpd reload

      

#############测试#############

[root@yun02 ~]# curl  yun01/p3/test
111111111111111

[root@yun02 ~]# curl  yun01/p3/test
22222222222

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值