上篇中提到对nginx7层(http和https)进行健康检查,使用的是淘宝的模块进行编译https://github.com/yaoweibin/nginx_upstream_check_module
但是此模块只支持nginx7层的健康检查,不支持4层UDP和TCP的健康检查。如果我们需要既支持4层又支持7层的健康检查模块,需要使用由另一位大神修改后的模块https://github.com/zhouchangxun/ngx_healthcheck_module
下面对配置文件中的配置进行解析
user nginx;
events {
worker_connections 1024;
}
http {
#下边server固定放在nginx配置文件中,主要用来做健康检查
#指定监听的ip 指定健康检查的访问路径和数据的展示格式为json,
#访问curl 127.0.0.1:9997/status 则所有健康检查的数据均能显示。获取数据代码解析json获取所需数据即可
server {
listen 127.0.0.1:9997;
location /status {
healthcheck_status json;
}
}
#正常监听器开始添加
server {
listen 192.168.11.2:800;
server_name test1;
location /{
proxy_pass http://test1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for