nginx负载均衡

下面都是在http{}里面进行配置

第一种配置:加权轮询,按服务器的性能给予权重

#负责压缩数据流
gzip  on;  
gzip_min_length   1000;  
gzip_types        text/plain text/css application/x-javascript;

#设定负载均衡的服务器列表
#weigth参数表示权值,权值越高被分配到的几率越大
upstream hello{
    server 192.168.68.43:8080 weight=1;
    server 192.168.68.45:8080 weight=1;            
}
   
server {
    #侦听的80端口
    listen       80;
    server_name  localhost;
    #设定查看Nginx状态的地址
    location /nginxstatus{
         stub_status on;
         access_log on;
         auth_basic "nginxstatus";
         auth_basic_user_file htpasswd;
    }
    #匹配以jsp结尾的,tomcat的网页文件是以jsp结尾
    location / {
        index index.jsp;
        proxy_pass   http://hello;    #在这里设置一个代理,和upstream的名字一样        
    }
}

第二种配置:ip_hash轮询方法,不可给服务器加权重

upstream lb {
	server 192.168.196.130 fail_timeout=20s;
	server 192.168.196.132 fail_timeout=20s;
	ip_hash;
}
 server {
	 listen 80;
	 server_name safexjt.com www.safexjt.com;
	 index index.html index.htm index.php;
	 location / {
		 proxy_pass http://lb;
		 proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;
		 include proxy.conf;
	 }
 }

转载于:https://my.oschina.net/qqlet/blog/1204452

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值