The question is how can I archive proxy_next_upstream.
Preferably I would like to return to lua with a error reason.
If the only way is to return several servers in upstream from lua, how
to
do so ?
I’m currently setting ngx.var.upstream and then proxy_pass http://$upstream.
I suppose the simplest method would be to set the $upstream in correct
format. But what about my preferably method?
On Wed, Sep 18, 2013 at 6:09 AM, Jedrzej Nowak wrote:
The question is how can I archive proxy_next_upstream.
Preferably I would like to return to lua with a error reason.
If the only way is to return several servers in upstream from lua, how to do
so ?
If you want to return the control back to Lua and let your Lua code do
the upstream retries or something, then you should use the
ngx.location.capture() API instead to initiate an Nginx subrequest to
ngx_proxy:
On Tue, Sep 24, 2013 at 2:35 AM, Jedrzej Nowak wrote:
The question is how can I do NOT redirect ?
Well, “rewrite … break” is not a redirect. It is just an internal
URI rewrite. That’s all.
I tried with @test instead of
/test but no success. Is there any other way to do that ?
Named locations can only work with internal redirects. They do not
support Nginx subrequests. You can ask the Nginx team to add support
for that to the Nginx core.
[...]
ngx.var.upstream = "192.168.1.10:9999"
res = ngx.location.capture('/test' .. ngx.var.request_uri,
{share_all_vars = true})
[…]
Please note that setting the “share_all_vars” to true for your
subrequests are genreally a bad idea. Because there could be really
bad side effects. In your example, all you need is to enable the
“copy_all_vars” option.
BTW, you may want to post such questions to the openresty-en mailing
list instead:
Yeah, I meant rewrite obviously… I would still prefer to not have even
rewrite if it’s possible.
I wonder why share_all_vars is not safe. Any serious consideration /
example / use case ? Why it’s better to copy them instead ? (What about
memory footprint etc).
And I will probably send the questions to openresty group too.
Yeah, I meant rewrite obviously… I would still prefer to not have even rewrite
if it’s possible.
It’s not worth saving at all. If you take an on-CPU Flame Graph for
your loaded Nginx worker processes, you’ll never even see it on the
graph. You’d better put your optimization efforts on something that is
truly measurable.
See also
I wonder why share_all_vars is not safe. Any serious consideration / example /
use case ? Why it’s better to copy them instead ? (What about memory footprint
etc).
Because of side effects involved in sharing variables between the
parent request and the subrequest. You can find such scary examples in
my Nginx tutorials (still under work!):