您好,登錄后才能下訂單哦!
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 / HTTP/1.1
User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh3/1.4.2
Host: baidu.com
Accept: /< HTTP/1.1 200 OK
< Date: Tue, 07 Jan 2020 08:29:28 GMT
< Server: Apache
< Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
< ETag: "51-47cf7e6ee8400"
< Accept-Ranges: bytes
< Content-Length: 81
< Cache-Control: max-age=86400
< Expires: Wed, 08 Jan 2020 08:29:28 GMT
< Connection: Keep-Alive
< Content-Type: text/html
<
以上返回表示支持 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 / HTTP/1.1
User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh3/1.4.2
Host: baidu.com
Accept: /< HTTP/1.1 200 OK
< Date: Tue, 07 Jan 2020 08:41:38 GMT
< Server: Apache
< Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
< ETag: "51-47cf7e6ee8400"
< Accept-Ranges: bytes
< Content-Length: 81
< Cache-Control: max-age=86400
< Expires: Wed, 08 Jan 2020 08:41:38 GMT
< Connection: Keep-Alive
< Content-Type: text/html
<
<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>
以上表示支持 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掉的機器就不會被代理轉發業務過去
從而保障業務的正常處理
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。