Tengine 主动式后端服务器健康检查功能 ngx_http_upstream_check_module
本文使用的版本:Tengine-2.3.3
在 Tengine 2.3.3 中 ngx_http_upstream_check_module 默认是不包含的,所以编译配置的时候需要手动添加上去
sudo apt install build-essential
./configure --add-module=modules/ngx_http_upstream_check_module
make
make 过后就可以在 objs 目录下找到 nginx 文件
check
upstream cluster1 {
# simple round-robin
server 192.168.0.1:80;
server 192.168.0.2:80;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_http_send "HEAD / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
upstream cluster2 {
# simple round-robin
server 192.168.0.3:80;
server 192.168.0.4:80;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_keepalive_requests 100;
check_http_send "HEAD / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
该模块生效范围是 upstream 中,上面的配置文件就是 每3s检查一次,5次失败->down 2次成功->up down后不再转发请求
check_status
server {
listen 80;
location /1 {
proxy_pass http://cluster1;
}
location /status {
check_status;
}
}
通过 check_status 命令显示服务器的健康状态页面,支持的格式有: html、csv、 json。默认类型是html。
/status?format=html
/status?format=csv
/status?format=json
标签:
Nginx
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律