- 默认,按时间轮询
请求按照时间顺序逐一分配到不同的后端服务器,挂掉一个就剔除(我测试的时候加载有点慢)
http {
upstream myproject {
server 127.0.0.1:8000;
server 127.0.0.1:8001;
}
server {
listen 80;
server_name www.domain.com;
location / {
proxy_pass http://myproject;
}
}
}
- 权重,指定轮询几率
weight和访问比率成正比,用于后端服务器性能不均的情况
http {
upstream myproject {
server 127.0.0.1:8000 weight=5;
server 127.0.0.1:8001 weight=7;
}
server {
listen 80;
server_name www.domain.com;
location / {
proxy_pass http://myproject;
}
}
}
- IP绑定,ip_hash
每个用户根据IP的hash值结果固定分配访问一个后端服务器(可以解决session问题)
http {
upstream myproject {
ip_hash;
server 127.0.0.1:8000;
server 127.0.0.1:8001;
}
server {
listen 80;
server_name www.domain.com;
location / {
proxy_pass http://myproject;
}
}
}