在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;
}
以上是一些常用的负载均衡策略,在实际应用中可以根据具体的需求选择合适的负载均衡策略。