Skip to content

Instantly share code, notes, and snippets.

@sabretus
Last active November 29, 2020 13:36
Show Gist options
  • Save sabretus/845b894fec2c80fbc7afe5d127eda3f8 to your computer and use it in GitHub Desktop.
Save sabretus/845b894fec2c80fbc7afe5d127eda3f8 to your computer and use it in GitHub Desktop.
Advanced Openresty health check for multiple backends using LUA
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