作者:小攸罗曼史 | 来源:互联网 | 2014-05-28 09:40
http{upstreamwww.server110.com{server10.1.165.36:80weight3;server10.249.198.235;server10.1.168.1down;server10.1.168.2backup;#ip_hash;}server{location/{proxy_pas
http
{
upstream www.server110.com {
server 10.1.165.36:80 weight = 3;
server 10.249.198.235;
server 10.1.168.1 down;
server 10.1.168.2 backup;
#ip_hash;
}
server
{
location / {
proxy_pass http://www.
server110.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Nginx
负载均衡需要添加 upstream 和在Server中添加proxy_pass
server 10.1.165.36:80 weight = 3; 代表这个服务器会有相同概率的3倍被访问
server 10.1.168.1 down; 暂时不使用
server 10.1.168.2 backup; 压力大的时候才会启动
ip_hash;通过IP地址进行hash匹配。但是会有一些弊端,比如Nginx不在最外层的话就无法获取IP等
proxy_pass http://www.
server110.com 代表访问的网址