Nginx 配置为负载均衡器(Version:1.14.2)

2019-03-26  本文已影响0人  MicoCube

介绍

负载均衡方法

nginx支持以下负载平衡机制(或​​方法):

默认负载均衡配置

使用nginx进行负载平衡的最简单配置可能如下所示:

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

    server {
        listen 80;

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

最小连接负载平衡

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

会话持久性

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;
}
上一篇下一篇

猜你喜欢

热点阅读