nginx 平衡策略

nginx 负载均衡有 (轮询策略,加权轮询)、最少链接数、ip-hash

轮询策略

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 {
        server srv1.example.com weight=3;
        server srv2.example.com;
        server srv3.example.com;
    }

最少链接数

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

ip-hash

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

但当有一个服务因为失败次数达到设置的阀值,会被nginx标记为错误的服务器,因而避免对他的访问
https://nginx.org/en/docs/http/load_balancing.html

你可能感兴趣的:(nginx 平衡策略)