400 028 6601

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

Nginxuptream健康检查

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掉的机器就不会被代理转发业务过去
从而保障业务的正常处理


网站标题:Nginxuptream健康检查
链接URL:http://mzwzsj.com/article/jichpp.html

其他资讯

让你的专属顾问为你服务