故障转移
原创...小于 1 分钟
当上游服务器(真实访问服务器),一旦出现故障或者是没有及时相应的话,应该直接轮训到下一台服务器,保证服务器的高可用。
http {
upstream back_end { # upstream 需要一个名字
server 127.0.0.1:8080 ;
server 127.0.0.1:8081 ;
ip_hash;
}
server {
listen 80;
server_name www.itmayiedu.com;
location / {
### 指定上游服务器负载均衡服务器
proxy_pass http://back_end;
#故障转移的条件:如果后端的服务器返回502、504、执行超时等错误,自动将请求转发到upstream负载均衡池中的另一台服务器,实现故障转移。
proxy_next_upstream http_502 http_504 error timeout invalid_header;
###nginx与上游服务器(真实访问的服务器)超时时间 后端服务器连接的超时时间_发起握手等候响应超时时间
proxy_connect_timeout 1s;
###nginx发送给上游服务器(真实访问的服务器)超时时间
proxy_send_timeout 1s;
### nginx接受上游服务器(真实访问的服务器)超时时间
proxy_read_timeout 1s;
index index.html index.htm;
}
}
}
Powered by Waline v2.15.7