nginx反向代理三台web服务器,实现负载均衡

步骤:

1 [root@localhost ~]# vim /usr/local/nginx-1.12.0/conf/nginx.conf
[root@localhost ~]# cp /usr/local/nginx-1.12.0/conf/nginx.conf /usr/local/nginx-1.12.0/conf/nginx1.conf
[root@localhost ~]# vim /usr/local/nginx-1.12.0/conf/nginx1.conf
[root@localhost ~]# vim /usr/local/nginx-1.12.0/html/index.html
[root@localhost ~]# cd /usr/local/nginx-1.12.0/sbin/
[root@localhost sbin]# /usr/local/nginx-1.12.0/sbin/nginx -c /usr/local/nginx-1.12.0/conf/nginx.conf
[root@localhost sbin]# /usr/local/nginx-1.12.0/sbin/nginx -c /usr/local/nginx-1.12.0/conf/nginx1.conf

修改nginx.conf

    upstream songwei{
        server 192.168.16.39:8080;
        server 192.168.16.110:8080;#在http和server之间加入这个模块
        server 192.168.16.121:8080;
    }
##后面的serever也得改

nginx.conf的server

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
           proxy_pass http://songwei;
           # root   html;
           #index  index.html index.htm;
        }

修改nginx1.conf(第一个从机)因为我主机作为代理服务器和从机1,所以这样设置

    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {


           root   html;
           index  index.html index.htm;
        }

修改nginx.conf(第二个从机)

  server {
        listen       8080;#只修改这里
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

同理修改第三个从机的nginx.conf

修改index.html

然后重启就ok

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值