NGINX 故障处理
1,什么情况下需要故障处理
比如连接超时
2,怎么处理?
出现故障的时候,有个幂等算法的概念,会不停的去重试请求其他的服务器
所以,处理数据变更的时候不要用get 方法,get会不停的重新请求 ,post一般不会当然如
服务器直接挂掉了也会重新请求
方案: 1,设置重复请求的总时间,总次数;
server{
proxy_red_timeout 10s;
proxy_next_upstream error timeout;
proxy_next_upstream_tries 3;
proxy_next_upstream_timeout 60s;
}
3,熔断机制 当某台被代理服务器处理请求,出现一定次数的错误(可配置)的情况下
,Nginx 在一定时间(可配置内),不在请求分配给该服务器处理。过来熔断时间后,nginx 会再次尝试分配一次请求给
该服务器处理,如果还是失败,则据需熔断。
Upstream 指令快中 server定义的熔断参数配置:
max_fails= number -熔断机制的错误次数 阀值(默认为1)
fail_timeout=time -熔断时间(nginx标记服务器不可用的持续时间,默认为10秒)
配置实例: server 192.168.1.100 max_fails=3 fail_timeout=10s;
events{}
http{
upstream tomcat_servers{
server 192.168.1.100:8081 weight=3 max_fails=3 fail_timeout=10s;
server 192.168.1.109: 8082 weight=2 max_fails=3 fail_timeout=10s;
}
server{
proxy_red_timeout 10s;
proxy_next_upstream error timeout;
proxy_next_upstream_tries 3;
proxy_next_upstream_timeout 60s;
location /{
proxy_set_header Host $http_host;
proxy_pass http://tomcat_servers;
}
location ~ \.(gif|jpg|png|css|js|html)${
root /data/www;
}
}
}