假设您有 2 个 Web 服务器。两个服务器都安装了 NginX。您想在它们之间平衡流量。如何在 nginx.conf 中做到这一点?
服务器1:
http {
upstream myproject {
ip_hash;
server 127.0.0.1:8000;
server 10.0.0.2:8000;
}
server {
listen 80;
server_name www.domain.com;
location / {
proxy_pass http://myproject;
}
}
}
服务器2:
http {
upstream myproject {
ip_hash;
server 127.0.0.1:8000;
server 10.0.0.1:8000;
}
server {
listen 80;
server_name www.domain.com;
location / {
proxy_pass http://myproject;
}
}
}
这应该有效还是彻底失败?