balancer_by_lua and proxy_next_upstream/set_more_tries

218 views
Skip to first unread message

RJoshi

unread,
Jun 14, 2016, 10:56:40 AM6/14/16
to openresty-en
Hello,

  Based on the proxy_next_upstream, Nginx can retry to the next configure server in the upstream directive.  
  How can we achieve this with balancer_by_lua?  It allows to set only one peer host/port.

Thanks,
Rohit Joshi

Scott Francis

unread,
Jun 14, 2016, 9:31:08 PM6/14/16
to openresty-en
The `set_more_tries` function can allow `balancer_by_lua` to be invoked multiple times during a single request. For example, if you call `set_more_tries(1)` before the request is sent to the upstream, if the upstream request fails with a status code configured in `proxy_next_upstream`, `balancer_by_lua` will be called again for the request. You can continue to call `set_more_tries`, and NGINX will continue to invoke `balancer_by_lua` on failures until you've reached `proxy_next_upstream_tries` at which point the downstream request will fail.

It's up to you to decide how to respond to a failing upstream. You can call `set_current_peer` and simply set different host/port upstream if/when the upstream request fails.

RJoshi

unread,
Jun 15, 2016, 11:03:21 AM6/15/16
to openresty-en
Thanks. It works fine.
Reply all
Reply to author
Forward
0 new messages