mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-04 20:57:38 +08:00
[ADD] add upstream tmpl
This commit is contained in:
parent
b78aa6e9a9
commit
823d1c9a95
@ -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 }}
|
Loading…
Reference in New Issue
Block a user