I know there are Nginx phases. Why does the following snippet deliver the "200 Host: example.com" instead of forwarding to Google? What would be a generally valid workaround to evaluate Lua higher or before?
server
{
listen 80;
server_name example.com;
location /
{
rewrite_by_lua_block
{
return ngx.redirect('https://www.google.com/', 303)
}
default_type text/plain;
return 200 "Host: $host";
}
}
Maybe this doesn't make sense at first sight, but I have an intelligent way to block/redirect certain calls in the Lua block (or in a Lua file included at this point). This module should work in general. With proxy_pass, alias etc. it works fine. Only with return 200 it does not work. Does anyone have an idea?
https://github.com/openresty/lua-nginx-module#rewrite_by_lua
So
return 200
always executes beforerewrite_by_lua_block
.In your case you should stick to
rewrite_by_lua_block
(didn't check)Credits to Alexey Ten.
As an intermediate conclusion (until proven otherwise), instead of using Nginx code directly, I must implement return 200 in Lua.
This is not what I want, but I had asked for a workaround. If anyone has a better one, go ahead.