192.168.96.128 负责负载均衡
192.168.96.129 应用服务器1
192.168.96.130 应用服务器2
我需要在www.test.vm域名上配置负载均衡。
在负责负载均衡(192.168.96.128)上配置
在http块中添加
upstream www.test.vm{
server 192.168.96.129:80; #vm1
server 192.168.96.130:80; #vm2
}
在配置localhost的server中添加
location / {
#root html;
#index index.html index.htm;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_pass http://$host;
}
负责负载均衡的机器上配置结束,重启nginx
还需要在2台应用服务器上进行www.test.vm的主机域名配置。配置完后重启nginx
在本机上绑定host,把www.test.vm指向192.168.96.128,然后在浏览器中访问www.test.vm