Nginx配置反向代理+负载均衡

Nginx配置反向代理

代码:
upstream tomcatserver1 {
	server 192.168.25.141:8080;
    }
    upstream tomcatserver2 {
	server 192.168.25.141:8081;
    }
   server {
        listen       80;
        server_name  8080.itheima.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://tomcatserver1;
            index  index.html index.htm;
        }

        
    }
    server {
        listen       80;
        server_name  8081.itheima.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://tomcatserver2;
            index  index.html index.htm;
        }

        
    }

负载均衡配置

代码:
upstream tomcatserver1 {
	server 192.168.25.141:8080;
        server 192.168.25.141:8081;  #此处为添加的服务器
    }
    upstream tomcatserver2 {
	server 192.168.25.141:8081;
    }
   server {
        listen       80;
        server_name  8080.itheima.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://tomcatserver1;
            index  index.html index.htm;
        }

        
    }
    server {
        listen       80;
        server_name  8081.itheima.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://tomcatserver2;
            index  index.html index.htm;
        }

        
    }

配置负载均衡的权重

节点说明:

在http节点里添加:

 

#定义负载均衡设备的 Ip及设备状态

upstream myServer {   

 

    server 127.0.0.1:9090 down;

    server 127.0.0.1:8080 weight=2;

    server 127.0.0.1:6060;

    server 127.0.0.1:7070 backup;

}

 

在需要使用负载的Server节点下添加

 

proxy_pass http://myServer;

 

upstream 每个设备的状态:

 

down 表示单前的server暂时不参与负载

weight  默认为1.weight越大,负载的权重就越大。

max_fails :允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误

fail_timeout:max_fails 次失败后,暂停的时间。

backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值