Last active
November 29, 2020 13:36
-
-
Save sabretus/845b894fec2c80fbc7afe5d127eda3f8 to your computer and use it in GitHub Desktop.
Advanced Openresty health check for multiple backends using LUA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
access_by_lua_block { | |
local http = require "resty.http" | |
local h = http.new() | |
h:set_timeout(2 * 1000) | |
local url = "http://127.0.0.1:18086/ping" | |
local res, err = h:request_uri(url, {method = "GET"}) | |
if err or not res or res.status ~= 204 then | |
ngx.status = ngx.HTTP_SERVICE_UNAVAILABLE | |
ngx.exit(ngx.HTTP_OK) | |
end | |
url = "http://127.0.0.1:9096/ping" | |
res, err = h:request_uri(url, {method = "GET"}) | |
if err or not res or res.status ~= 200 then | |
ngx.status = ngx.HTTP_SERVICE_UNAVAILABLE | |
end | |
ngx.exit(ngx.HTTP_OK) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment