Nginx uptream健康检查

发布时间:2020-03-04 00:49:52 作者:Pro168
来源:网络 阅读:240

upstream hello {
server 100.14.1.3:1201;
server 100.14.1.4:1201;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_http_send "HEAD /product HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
server {
listen 80;
server_name hello.youbest.com;
access_log /data/logs/nginx/hello.youbest.com.access.log main;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://hello;
}
}

首先要确认服务类型是 http 还是tcp

 check interval=3000 rise=2 fall=5 timeout=1000 type=http; 

 or

 check interval=3000 rise=2 fall=5 timeout=1000 type=tcp;

 然后确认健康检查的url是否支持 HEAD请求或者GET 请求

 [root@100-14-1-3 ~]# curl -v -XHEAD http://hello.youbest.com/product

以上返回表示支持 HEAD 请求 nginx 就可以这样做健康检查

    check interval=3000 rise=2 fall=5 timeout=1000 type=http;
    check_http_send "HEAD /product HTTP/1.0\r\n\r\n";
    check_http_expect_alive http_2xx http_3xx;

其中 /product 表示服务里面的埋点路径

< HTTP/1.1 200 OK 表示返回200状态

如果HEAD 请求不支持 参考下面baidu.com的GET 请求

[root@vhs100-14-1-3 ~]# curl -v -XGET http://baidu.com

以上表示支持 GET 请求 nginx 就可以这样做健康检查

    check interval=3000 rise=2 fall=5 timeout=1000 type=http;
    check_http_send "GET /product HTTP/1.0\r\n\r\n";
    check_http_expect_alive http_2xx http_3xx;

加了健康检查后,当后端有多台服务器提供服务时
Down掉的机器就不会被代理转发业务过去
从而保障业务的正常处理

推荐阅读:
  1. CentOS7.2 nginx1.10.1 增加后端健康检查upstream_check模塊
  2. Nginx中http运行状况健康检查配置的示例分析

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

nginx 健康检查 ginx ea

上一篇:TiKV 源码解析系列文章(十一)Storage - 事务控

下一篇:K8S——ETCD部署

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》