Nginx一般性负载均衡配置
server { listen 80; server_name bbs.liaoxiang.com; #charset koi8-r; #access_log logs/host.access.log main; upstream myupstream { #weight 值越大,负载权重越大,请求次数越多 #max_fails 允许请求失败的次数,超过失败次数后,转发到下一个服务器,当有max_fails个请求失败,就表示后端的服务器不可用,默认为1,将其设置为0可以关闭检查 #fail_timeout 指定时间内无响应则失败, 在以后的fail_timeout时间内nginx不会再把请求发往已检查出标记为不可用的服务器 #down 表示当前server不参与负载 #backup 其他非backup server都忙的时候,backup server作为备用服务器,将请求转发到backup服务器 server 192.168.10.150:8080 weight=1 max_fails=2 fail_timeout=30s; server 192.168.10.151:8080 weight=2 max_fails=2 fail_timeout=30s; server 192.168.10.152:8080 down; #server 192.168.10.153:8080 myupstream; } location / { proxy_pass http://myupstream; index index.html index.htm; #这里配置宕机检测,都设置为1秒,这是有了负载均衡过后配置的,如果访问时挂了一个服务器,1秒不响应就自动切换到另外应用服务器进行访问 proxy_connect_timeout 1; proxy_send_timeout 1; proxy_read_timeout 1; }
该配置拥有加权轮询,宕机检测,请求自动转发等功能
浙公网安备 33010602011771号