nginx 负载均衡实现

nginx的配置内容 是用了lnmp 环境,在此基础上的修改

 开启了两个服务器,

192.168.56.102:8080

192.168.56.1:81

# 添加服务器列表,真实对应的服务器都在下面
# weight 权重,数字越大,被分配的可能性越高
# Nginx基于连接探测,如果发现后端异常,在单位周期为fail_timeout设置的时间,中达到max_fails次数,这个周期次数内,如果后端同一个节点不可用,那么接将把节点标记为不可用,并等待下一个周期(同样时常为fail_timeout)再一次去请求,判断是否连接是否成功
# 真实服务器中 一旦有一台服务器出现故障,不去及时处理的情况下,访问过程中,总有那么几次速度很慢。(因为已fail_timeout为周期,周期一过,故障服务器又会有被分配到的可能。)
upstream new_pool { server 192.168.56.102:8080 weight=4 max_fails=1 fail_timeout=10s; server 192.168.56.1:81 weight=4 max_fails=1 fail_timeout=1
0s; } server { listen 80; server_name www.new.com ; location / { proxy_pass http://new_pool; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } include rewrite/none.conf; include enable-php.conf; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { proxy_pass http://new_pool; # 图片代理 expires 30d; } location ~ .*\.(js|css)?$ { proxy_pass http://new_pool; # js/css 代理 expires 12h; } location ~ /.well-known { allow all; } location ~ /\. { deny all; } access_log off; }

 本文参考:https://www.cnblogs.com/youzhibing/p/7327342.html

猜你喜欢

转载自www.cnblogs.com/xiaobaiskill/p/9983093.html