在NGINX脚本中处理重定向字符串,可以吗?



我正在寻找一个"完整的 NGINX 解决方案",没有中间重定向......但是我需要"我的姓名解析器"进行一些外部处理,如这个execute幻想所示:

server {
server_name resolver.mydomain.com;
execute xx = http://localhos:123456/myNameResolver/$request_uri;
rewrite ^ http://www.adifferentdomain.com$xx? permanent;
}

那么,有没有可能做这样的事情?也许使用一种fastcgi_pass,但只返回一个字符串,而不是绕过所有的HTTP解析。

好吧,你可以使用HttpLuaModule,它可以执行命令并在需要时将它们存储在变量中。

location / {
server_name resolver.mydomain.com;
# Get response via lua script.
set_by_lua_file $xx 'resolver-script.lua' $request_uri;
rewrite ^ http://www.adifferentdomain.com$xx? permanent;
}

你只需要一个Lua脚本来为你做你的请求,尝试这样的事情,使用你的$request_uri作为arg[1],因为它被认为是一个命令行参数

最新更新