ngx_http_healthcheck_module
参考自:nginx负载集群解决方案
upstream provider {
server 192.168.237.186:10086;
healthcheck_enabled;
healthcheck_delay 10000;
healthcheck_timeout 1000;
healthcheck_failcount 2;
healthcheck_send 'GET /test HTTP/1.0' 'Host: xxcupid1.qunar.com' 'Connection: close';
}
healthcheck_enabled ##启用此模块
如果healthcheck_send配置的地址无法访问,nginx的error日志中会打印如下内容:
2016/09/12 15:48:06 [info] 5831#0: check protocol qunar_http error with peer: 192.168.237.186:10086
如果能正常访问的话
2016/09/12 15:51:02 [info] 6974#0: enable check peer: 192.168.237.186:10086
nginx关闭启动日志:
2016/09/12 15:50:39 [error] 5831#0: ngx_exiting...
2016/09/12 15:50:39 [error] 5831#0: Pending timer: 1616 handler addr: (4bc6d7)
2016/09/12 15:50:41 [notice] 5831#0: clear all the events on 5831
2016/09/12 15:50:41 [error] 5831#0: ngx_exiting...
2016/09/12 15:50:41 [error] 5831#0: Pending timer: -1 handler addr: (0)
2016/09/12 15:50:41 [notice] 5831#0: exiting
2016/09/12 15:50:41 [notice] 5831#0: exit
2016/09/12 15:50:41 [notice] 18102#0: signal 17 (SIGCHLD) received
2016/09/12 15:50:41 [notice] 18102#0: worker process 5831 exited with code 0
2016/09/12 15:50:41 [notice] 18102#0: signal 29 (SIGIO) received
location /name {
#proxy_pass http://provider;
proxy_pass http://192.168.237.186:10086/;
proxy_set_header Host $host;
proxy_set_header X-Real-Scheme $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header
proxy_set_header Host $proxy_host;
proxy_set_header Connection close;
If caching is enabled, the header fields “If-Modified-Since”, “If-Unmodified-Since”, “If-None-Match”, “If-Match”, “Range”, and “If-Range” from the original request are not passed to the proxied server.
proxy_set_header Host $http_host;
However, if this field is not present in a client request header then nothing will be passed. In such a case it is better to use the $host variable - its value equals the server name in the “Host” request header field or the primary server name if this field is not present:
proxy_set_header Host $host;
In addition, the server name can be passed together with the port of the proxied server:
proxy_set_header Host $host:$proxy_port;
If the value of a header field is an empty string then this field will not be passed to a proxied server:
proxy_set_header Accept-Encoding "";