负载均衡7层Nginx(提供软件包)
Nginx proxy 利用 proxy 基本可以实现一个完整的 7 层负载均衡。
Client eth0: 192.168.122.1/24
Nginx eth0:192.168.122.254/24
HTML 1 eth0 192.168.122.10/24
HTML 2 eth0 192.168.122.20/24
PHP 1 eth0 192.168.122.30/24
PHP 2 eth0 192.168.122.40/24
HTML 1和2
# yum install httpd
分别创建测试页面index.html ,开启服务
PHP 1和2
# yum install httpd
分别创建测试页面index.php ,开启服务
安装配置Nginx
# rpm -ivh nginx-0.6.36-1.el5.i386.rpm
# vim /etc/nginx/nginx.conf
location/ {
root/usr/share/nginx/html;
indexindex.html index.htm;
if($request_uri ~* \.html$) {
proxy_passhttp://htmlserver;
}
if($request_uri ~* \.php$) {
proxy_passhttp://phpserver;
}
}
# vim /etc/nginx/conf.d/test.conf
upstream htmlserver {
server192.168.122.10;
server192.168.122.20;
}
upstream phpserver {
server192.168.122.30;
server192.168.122.40;
}
# service nginx start
在客户端访问 HAproxy测试
# elinks –dump http:// 192.168.122.254
# elinks –dump http://192.168.122.254/index.html
# elinks –dump http://192.168.122.254/index.php
可以只做2个html进行测试访问192.168.122.254/index.html 不停地刷新清楚历史记录会分别看到html 1和2 的网页
软件包看其他博文最下面的百度云盘的地址