基于apache的反向代理和负载均衡

这个是apache2.2以后增加的新的特性。

首先我们这边有2个域名。一个是www.timo.com还有一个是mail.timo.com这两个域名。同时www.zauc.com内网有2台机器 (192.168.0.10和192.168.0.11),当然也可以是外网.mail.zauc.com这个域名的内网IP为 (192.168.0.20)

要使用proxy和blance一定要在编译的时候加入proxy和blance.


 ./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --enable-modules=all --enable-proxy --enable-proxy-connect --enable-proxy-ftp --enable-proxy-http --enable-proxy-ajp --enable-proxy-balancer --enable-vhost-alias make make install

安装完成后在extra/httpd-vhosts.conf中进行如下配置。


 ServerAdmin [email protected] ServerName www.timo.com ProxyPass / balancer://www.timo.com/ ErrorLog "logs/www.timo.com-error_log" CustomLog "logs/www.timo.com-access_log" common

 ServerAdmin [email protected] ServerName mail.timo.com ProxyPass / http://192.168.0.20/ ProxyPassReverse / http://192.168.0.20/ ErrorLog "logs/mail.timo.com-error_log" CustomLog "logs/mail.timo.com-access_log" common

www.timo.com还需要在httpd.conf进行配置


ProxyRequests Off BalancerMember http://192.168.0.10 loadfactor=1  
BalancerMember http://192.168.0.11 loadfactor=1

这里只是简单的一个配置。详细的可以参考下apache2.2中文文档中的说明