1、反向代理配置
1.1配置upstream
upstream [proxyName] { server 192.168.1.173:8080; server 192.168.1.174:8080; server 192.168.1.175:8080; }
1.2配置server
server { listem 80; server_name www.tomcats.com;
location / {
proxy_pass http://tomcats;
}
}
2、负载均衡配置
2.1使用加权轮询
upstream [proxyName] { server 192.168.1.173:8080 weight=1; server 192.168.1.174:8080 weight=5; server 192.168.1.175:8080 weight=2; }
2.2hash负载均衡
upstream [proxyName] { ip_hash
server 192.168.1.173:8080;
server 192.168.1.174:8080;
server 192.168.1.175:8080;
}
hash算法实际上只会计算 192.168.1这段做哈希
使用ip_hash的注意点:
upstream [proxyName] { hash $request_url;
server 192.168.1.173:8080;
server 192.168.1.174:8080;
server 192.168.1.175:8080;
}
2.4最小连接负载均衡
upstream [proxyName] { least_conn;
server 192.168.1.173:8080;
server 192.168.1.174:8080;
server 192.168.1.175:8080;
}