nginx初步负载均衡

vm镜像:centos6.6

域名服务已配好

web01ip:192.168.146.134 www.abc.cn/bbs.abc.cn

web02ip:192.168.146.135 www.abc.cn/bbs.abc.cn

nginx主配ip:192.168.146.132

nginx副配ip:192.168.146.133


1.对web01和web02主机nginx配置:

1.1 编译安装nginx后

cd /application/nginx/

1.2 mkdir html/{www bbs}

echo "web01 www.abc,cn">html/www/index.html

echo "web01 bbs.abc,cn">html/bbs/index.html

同样在web02主机建立

echo "web02 www.abc,cn">html/www/index.html

[root@web01 nginx]# cat conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    server {
        listen       80;
        server_name  www.abc.cn;
        location / {
            root   html/www;
            index  index.html index.htm;
        }
        access_log  logs/www.access.log  main;
	}
    server {
        listen       80;
        server_name  bbs.abc.cn;
        location / {
            root   html/bbs;
            index  index.html index.htm;
        }
        access_log  logs/bbs.access.log  main;
	}
}

 

/application/nginx/sbin/nginx -t

......is ok

启动:(不启动会报invalid pid ...nginx.pid之类的)

/application/nginx/sbin/nginx

1.2加入web01/web02主机解析

[root@localhost ~]# cat /etc/hosts
192.168.146.134 www.abc.cn
192.168.146.134 bbs.abc.cn

2.对nginx主配和nginx副配nginx.conf编辑相同如下:

[root@localhost nginx]# cat conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    upstream www_server_pools{		#<==定义web服务器池,包含134,135两个web节点
    server 192.168.146.134:80 weight=1;
    server 192.168.146.135:80 weight=1;
}
    server {		#<==定义代理的负载均衡域名虚拟主机
        listen       80;
        server_name  www.abc.cn;
        location / {	        
  proxy_pass http://www_server_pools;		#<==访问www.abc.cn,请求发送给www_server_pools里的节点
}
  }
}


2.1对ip192.168.146.132主配nginx编辑

echo “192.168.146.132 www.abc.cn >/etc/hosts

curl www.abc.cn
web01 www.abc,cn
curl www.abc.cn
web02 www.abc,cn


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值