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;
}
}
First make sure the service type is http or 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
- About to connect() to hello.youbest.com port 80 (#0)
- Trying 10.24.1.3... connected
- Connected to hello.youbest.com (100.14.1.3) port 80 (#0)
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 libssh2/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 request returns expressed support for more than nginx can do so health check
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;
Wherein / product represents the path inside the service Buried
<HTTP / 1.1 200 OK state 200 represents return
If the HEAD request is not supported by reference to the following GET request baidu.com
[root@vhs100-14-1-3 ~]# curl -v -XGET http://baidu.com
- About to connect() to baidu.com port 80 (#0)
- Trying 220.181.38.148... connected
- Connected to baidu.com (220.181.38.148) port 80 (#0)
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 libssh2/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> - Connection #0 to host baidu.com left intact
- Closing connection #0
More support GET request nginx can do so health check
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;
Plus a health examination, when more than one back-end server provides services
Down out of the machine will not be the last agency to forward traffic
normally processed in order to protect business