Answer the question
In order to leave comments, you need to log in
How to organize nginx condition check?
There is a task to check the parameter in the address bar and, depending on the value, either process it in the current server section or redirect to another server.
The check happens with the help of lua, but it is not possible to send a request further.
Tried the following options:
rewrite_by_lua_block {
ngx.exec("@asd")
}
location @asd {
echo "asd";
}
set $new "0";
rewrite_by_lua_block {
ngx.var.new="1"
}
if ($new = "1") {
rewrite ^(.*)$ /to_new_server/$1;
}
location / {
echo "no";
}
location /to_new_server/ {
echo "asd";
}
ngx.req.set_uri("/to_new_server", true)
local uri = ngx.re.sub(ngx.var.uri, "^(.*)$", "/to_new_server/$1")
ngx.req.set_uri(uri)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question