1、nginx配置文件增加配置节
location /a {
default_type 'text/html';
lua_code_cache on;
rewrite_by_lua_file /data/lua/a.lua;
}
location @b {
default_type 'text/html';
lua_code_cache on;
content_by_lua_file /data/lua/b.lua;
}
location @c {
default_type 'text/html';
lua_code_cache on;
content_by_lua_file /data/lua/c.lua;
}
vi a.lua
ngx.req.read_body()
local args, err = ngx.req.get_post_args()
if args["t1"]==nil then
ngx.req.set_uri_args("t1=ccc")
ngx.exec("@b")
else
ngx.req.set_uri_args("t1=ccc")

本文介绍了如何在openresty中通过配置nginx和lua脚本来根据请求参数进行重定向。示例展示了当参数`t1`不存在时重定向到`@b`,存在时重定向到`@c`。同时,`b.lua`和`c.lua`展示如何获取并显示POST参数、GET参数及HTTP头信息。
最低0.47元/天 解锁文章
1896

被折叠的 条评论
为什么被折叠?



