From 823d1c9a95c004a1df1d278651ec09994492d200 Mon Sep 17 00:00:00 2001 From: GLYASAI Date: Sat, 1 Dec 2018 13:52:15 +0800 Subject: [PATCH] [ADD] add upstream tmpl --- .../nginxtmp/tmpl/upstreams-http-rbd.tmpl | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 hack/contrib/docker/gateway/nginxtmp/tmpl/upstreams-http-rbd.tmpl diff --git a/hack/contrib/docker/gateway/nginxtmp/tmpl/upstreams-http-rbd.tmpl b/hack/contrib/docker/gateway/nginxtmp/tmpl/upstreams-http-rbd.tmpl new file mode 100644 index 000000000..aadcccd8f --- /dev/null +++ b/hack/contrib/docker/gateway/nginxtmp/tmpl/upstreams-http-rbd.tmpl @@ -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 }} \ No newline at end of file