#三、负载均衡
#配置语法
Syntax: upstream name {...};
Default : ——
Context:http
#样例
#upstream backend{
# server backend1.example.com weight=5;
# server backend2.example.com:8080;
# server backend3.example.com ;
# server unix:/tmp/backend3;
#
# server backup1.example.com:8080 backup;
# server backup2.example.com:8080 backup;
#}
#down 当前的server暂时不参与负载均衡
#backup 预留的备份服务器
#max_fails 允许请求失败的次数
#fail_timeout 经过max_fails失败后,服务器暂停时间
#max_counts 限制最大的连接的连接数
#调度算法:
#轮询 按时间顺序逐一分配到不同的后端服务器
#例:
#upstream backend{
# server backend1.example.com;
# server backend2.example.com;
# server backend3.example.com;
#}
#加权轮询 weight值越大,分配到的访问几率越高
#upstream backend{
# server backend1.example.com weight=5;
# server backend2.example.com;
# server backend3.example.com;
#ip_hash 每个请求按访问IP的hash结果分配,这样来自同一个IP的固定访问一个后端服务器
#upstream backend{
# ip_hash;
# server backend1.example.com;
# server backend2.example.com;
# server backend3.example.com;
#}
#least_conn 最少连接数,哪个机器连接数少就分发
#upstream backend{
# least_conn;
# server backend1.example.com;
# server backend2.example.com;
# server backend3.example.com;
#}
#url_hash 按照访问的URL的hash结果来分配请求,使每个URL定向到同一个后端服务器
#upstream backend{
# url_hash;
# server backend1.example.com;
# server backend2.example.com;
# server backend3.example.com;
#}
#hash关键数值 hash自定义的key
#Syntax: hash key [consistent];
#Default : ——
#Context:upstream
#upstream backend{
# hash $request_uri;
# server backend1.example.com;
# server backend2.example.com;
# server backend3.example.com;
#}