創建一個指向服務器本身的localhost站點(127.0.0.1)和一個指向服務器的站點,域名和IP都可以。
I.對域名站點配置:
upstream myproj { server 127.0.0.1:81 weight=1; server 127.0.0.1:82 weight=2; } server { listen 80; server_name www.realmid.cn; index index.php index.html index.html default.php default.htm root /www/wwwroot/realmid.cn location / { proxy_pass http://mypro } }
II.對127.0.0.1站點進行配置:
具體操作:將server{...}復制粘貼一份,然后進行兩個server配置,分別指向需要負載均衡的兩個服務器站點。若是有多份,可以多復制幾份server{...}配置
就這樣,就能成功負載均衡了。