1 Star 0 Fork 0

流动de云 / ngx_healthcheck_module

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
nginx.conf.example 2.83 KB
一键复制 编辑 原始数据 按行查看 历史
#user root;
worker_processes 1;
error_log logs/error.log info;
#error_log logs/debug_stream.log debug_stream;
error_log logs/debug_http.log debug_http;
#pid logs/nginx.pid;
events {
worker_connections 256;
}
http {
log_format main '$remote_addr:$remote_port -> $server_addr:$server_port [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
server {
listen 8081;
# status interface
location /status {
healthcheck_status json;
}
# http front
location / {
proxy_pass http://http-cluster;
}
}
# as a backend server1.
server {
listen 127.0.0.1:8082;
location / {
default_type application/json ;
return 201 '{"name":"server1","status": "UP"}';
}
}
# as a backend server2.
server {
listen 127.0.0.2:8082;
location / {
default_type application/json ;
return 202 '{"name":"server2","status": "DOWN"}';
}
}
upstream http-cluster {
# simple round-robin
server 127.0.0.1:8082;
server 127.0.0.2:8082;
check interval=3000 rise=2 fall=5 timeout=5000 type=http;
check_http_send "GET /heartbeat HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
# I just wanna enable servers whose response content contain ('server1' or 'server3') and 'UP'
check_http_expect_body ~ "server[13].+UP";
}
}
stream {
upstream tcp-cluster {
# simple round-robin
server 127.0.0.1:22; # nomarl
server 192.168.0.2:22;
check interval=3000 rise=2 fall=5 timeout=5000 default_down=true type=tcp;
#check_http_send "UDP_TEST";
}
upstream udp-cluster {
# simple round-robin
server 127.0.0.1:5432; # port unreachable
server 8.8.8.8:5432; # no error icmp msg
check interval=3000 rise=2 fall=5 timeout=5000 default_down=true type=udp;
check_http_send "UDP_TEST";
}
upstream http-cluster2 {
# simple round-robin
server 127.0.0.1:8082;
server 127.0.0.2:8082;
check interval=3000 rise=1 fall=1 timeout=5000 type=http;
#check_http_send "GET /heartbeat2 HTTP/1.1\r\nHost: localhost\r\n\r\n";
check_http_send "GET /heartbeat2 HTTP/1.0\r\nConnection: Keep-Alive\r\n\r\n";
# when use keepalive, you must use HTTP/1.1 with Host like above, or use HTTP/1.0 with header 'Connection: Keep-Alive'
check_keepalive_requests 10;
check_http_expect_alive http_2xx http_3xx;
# I just wanna enable servers whose response content contain ('server1' or 'server3') and 'UP'
check_http_expect_body ~ "server[13].+UP";
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hrq/ngx_healthcheck_module.git
git@gitee.com:hrq/ngx_healthcheck_module.git
hrq
ngx_healthcheck_module
ngx_healthcheck_module
master

搜索帮助

Bbcd6f05 5694891 0cc6727d 5694891