nginx负载均衡配置

nginx负载均衡

一、nginx安装

详见:http://blog.csdn.net/zhengyong15984285623/article/details/53871752

二、负载均衡机制

least_conn、ip_hash;

在nginx中支持以下负载均衡机制:

  1. 轮询 - 向应用服务器的请求以循环方式分布,
  2. 最小连接 - 下一个请求分配给具有最少活动连接数的服务器,
  3. ip-hash - 散列函数用于确定应为下一个请求选择什么服务器(基于客户端的IP地址)。
三、负载均衡示例

轮询方式(默认):

http {
    upstream myapp1 {
        server srv1.example.com  max_fails=3  fail_timeout=30s;
        server srv2.example.com;
        server srv3.example.com;
    }

    server {
        listen       80;
        server_name  localhost;

        location / {
            proxy_pass http://myapp1;
        }
    }
}

最小连接:

upstream myapp1 {
    least_conn
    server srv1.example.com; 
    server srv2.example.com;
    server srv3.example.com;
}

hash方式:

upstream myapp1 {
    ip_hash;
    server srv1.example.com;
    server srv2.example.com;
    server srv3.example.com;
}

权重方式:

 upstream myapp1 {
    server srv1.example.com weight=3;
    server srv2.example.com;
    server srv3.example.com;
}
四、参考文档

参考文档地址:http://nginx.org/en/docs/http/load_balancing.html#nginx_load_balancing_configuration

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值