在Nginx中設置負載均衡的不同策略可以通過配置upstream塊來實現。以下是一些常用的負載均衡策略:
upstream backend {
server 192.168.1.100;
server 192.168.1.101;
server 192.168.1.102;
}
upstream backend {
server 192.168.1.100 weight=3;
server 192.168.1.101 weight=2;
server 192.168.1.102 weight=1;
}
upstream backend {
ip_hash;
server 192.168.1.100;
server 192.168.1.101;
server 192.168.1.102;
}
upstream backend {
least_conn;
server 192.168.1.100;
server 192.168.1.101;
server 192.168.1.102;
}
upstream backend {
hash $request_uri;
server 192.168.1.100;
server 192.168.1.101;
server 192.168.1.102;
}
以上是一些常用的負載均衡策略,在實際應用中可以根據具體的需求選擇合適的負載均衡策略。