1.轮询负载均衡
(需要请求 session时建议不要用 。如登录等)
upstream model{
server 127.0.0.1:8080
server 127.0.0.1:8081
server 127.0.0.1:8082
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass model;
proxy_redirect default;
}
}
2.权重负载均衡
upstream model{
server 10.0.0.10:8080 weight=5;
server 10.0.0.11:8080 weight=5;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass model;
proxy_redirect default;
}
}
3.hash负载均衡
(可解决SESSION一致性问题)
upstream model{
ip_hash;
server 10.0.0.10:8080;
server 10.0.0.11:8080;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass model;
proxy_redirect default;
}
}
4.fair负载均衡
按后端服务器的响应时间来分配请求
upstream model{
server 10.0.0.10:8080;
server 10.0.0.11:8080;
fair;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass model;
proxy_redirect default;
}
}
5.url_hash负载均衡
按访问url的hash结果来分配请求
upstream model{
server 10.0.0.10:8080;
server 10.0.0.11:8080;
hash $request_uri;
hash_method crc32;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass model;
proxy_redirect default;
}
}