假設您有 2 個網頁伺服器。兩者都安裝了 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;
}
}
}
這應該有效還是完全失敗?