Nginx搭建负载均衡集群
(1).实验环境 youxi1 192.168.5.101 负载均衡器 youxi2 192.168.5.102 主机1 youxi3 192.168.5.103 主机2 (2).Nginx负载均衡策略 nginx的负载均衡用于upstream模板定义的后端服务器列表中选取一台服务器接收用户的请求。一个基本的upstream模块如下: upstream [服务器组名称]{ server [IP地址]:[端口号]; server [IP地址]:[端口号]; .... } 在upstream模块配置完成后,要让指定的访问反向代理到服务器列表,格式如下: location ~ .*$ { index index.jsp index.html; proxy_pass http://[服务器组名称]; } 扩展:nginx的location配置规则: http://outofmemory.cn/code-snippet/742/nginx-location-configuration-xiangxi-explain 这样就完成了最基本的负载均衡,但是这并不能满足实际需求。目前Nginx的upstream模块支持6种方式的负载均衡策略(算法):轮询(默认方式)、weight(权重方式)、ip_hash(依据ip分配方式)、least_conn