1、基于轮询分发:根据请求流量均匀分发到后端服务器
upstream web {
server server1;
server server2;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://web;
}
}
2、基于主备分发:默认分发到主,主宕机后分发到备
upstream web {
server server1;
server server2 backup;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://web;
}
}
3、基于权重:通过配置权重,可以让性能好的服务器承担更多的负载
upstream web {
# 设置权重比例1:2
server server1 weight=1;
server server2 weight=2;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://web;
}
}
4、基于ip_hash分发:保证来自同样源地址的请求都分发到同一台主机
upstream web {
ip_hash; # 指定ip_hash即可,默认weight权重比例1: 1
server server1;
server server2;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://web;
}
}
标签:web,weight,分发,ip,server,Nginx,算法,pass From: https://www.cnblogs.com/tjane/p/16875056.html需要注意:ip_hash算法不支持backup、weight设置。默认权重为1