[ADD] add upstream tmpl

This commit is contained in:
GLYASAI 2018-12-01 13:52:15 +08:00
parent b78aa6e9a9
commit 823d1c9a95

View File

@ -0,0 +1,25 @@
{{ range $upstream := . }}
upstream {{$upstream.Name}} {
server 0.0.0.1;
balancer_by_lua_block {
local balancer = require "ngx.balancer"
local cjson = require("cjson")
local endpoints = cjson.decode(ngx.shared.upstreams_dict:get("{{$upstream.Name}}"))
local endpoint = endpoints[math.random(1,table.getn(endpoints))]
balancer.set_timeouts(1, 0.5, 0.5)
balancer.set_more_tries(2)
local ok, err = balancer.set_current_peer(
endpoint.Host, endpoint.Port
)
if not ok then
ngx.log(ngx.ERR, "failed to set peer: ", err)
return ngx.exit(500)
end
}
keepalive 10;
}
{{ end }}