lua-resty-upstream-healthcheck
lua-resty-upstream-healthcheck copied to clipboard
the problem of returning of healthcheck
my code in nginx.conf
upstream swordnet.com{
server 127.0.0.1:18080;#two tomcats have bean started
server 127.0.0.1:28080;
}
lua_shared_dict ngx_stats 500m;
lua_shared_dict healthcheck 1m;
lua_socket_log_errors off;
init_worker_by_lua_block {
local hc = require "resty.upstream.healthcheck"
local ok, err = hc.spawn_checker {
shm = "healthcheck",
type = "http",
upstream = "swordnet.com",
http_req = "GET /health.txt HTTP/1.0\r\nHost: swordnet.com\r\n\r\n",
valid_statuses = {200, 302}
}
if not ok then
ngx.log(ngx.ERR, "=======> failed to spawn health checker: ", err)
return
end
}
.................
location /server/status {
access_log off;
default_type text/plain;
allow 127.0.0.1;
deny all;
content_by_lua_block {
local hc = require "resty.upstream.healthcheck"
ngx.say("Nginx Worker PID: ", ngx.worker.pid())
ngx.print(hc.status_page())
}
}
when I visited the url http://localhost/server/status on browser. It showed as below:
Nginx Worker PID: 12158
Upstream swordnet.com
Primary Peers
127.0.0.1:18080 DOWN
127.0.0.1:28080 DOWN
Backup Peers
all the visiting became 502 gateway problems, and the error.log
no live upstreams while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://swordnet.com/", host: "localhost:81"
but when I changed the upstream = "swordnet.com" into something else but swordnet.com
everything became normal again but no matter what's the status tomcats was (started,stoped),It always showed as below:
Nginx Worker PID: 13742
Upstream swordnet.com (NO checkers)
Primary Peers
127.0.0.1:18080 up
127.0.0.1:28080 up
Backup Peers
+1