ngx_lua_API 指令详解(四)ngx.exec指令
2017-06-13 14:41
399 查看
https://github.com/openresty/lua-nginx-module#ngxexec
参照:http://blog.csdn.net/weiyuefei/article/details/38434797
在Nginx中实现重定向可以通过rewrite指令,具体可参考《Nginx学习——http_rewrite_module的rewrite指令》
通过Lua模块也可以实现同样的功能,Lua模块提供了相关的API来实现重定向的功能,
语法:
syntax: ngx.exec(uri, args?)
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
1、主要实现的是内部的重定向,等价于下面的rewrite指令 rewrite regrex replacement last;
curl http://192.168.18.180:8088/foo 输出为 goodbye
2、 args参数可以以string的形式给出,也可以以lua table的形式给出,如下所示:
3. 该方法不会主动返回,因此,强烈建议在调用该方法时,最好显示加上return,如下所示:
参照:http://blog.csdn.net/weiyuefei/article/details/38434797
在Nginx中实现重定向可以通过rewrite指令,具体可参考《Nginx学习——http_rewrite_module的rewrite指令》
通过Lua模块也可以实现同样的功能,Lua模块提供了相关的API来实现重定向的功能,
语法:
syntax: ngx.exec(uri, args?)
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
1、主要实现的是内部的重定向,等价于下面的rewrite指令 rewrite regrex replacement last;
location /foo { content_by_lua_block { ngx.exec("/bar", "a=goodbye"); } } location /bar { content_by_lua_block { local args = ngx.req.get_uri_args() for key, val in pairs(args) do if key == "a" then ngx.say(val) end end } }
curl http://192.168.18.180:8088/foo 输出为 goodbye
2、 args参数可以以string的形式给出,也可以以lua table的形式给出,如下所示:
location /foo { content_by_lua_block { ngx.exec("/bar", { a= 4, b="hello world"}); } } location /bar { content_by_lua_block { local args = ngx.req.get_uri_args() for key, val in pairs(args) do ngx.say(key.." = "..val) end } }
3. 该方法不会主动返回,因此,强烈建议在调用该方法时,最好显示加上return,如下所示:
return ngx.exec(...)
相关文章推荐
- ngx_lua_API 指令详解(二)ngx.re.match/find/gmatch/sub/gsub指令集合
- ngx_lua_API 指令详解(五)coroutine.create,coroutine.resume,coroutine.yield 等集合指令介绍
- ngx_lua_API 指令详解(一)ngx.timer.at 指令
- ngx_lua_API 指令详解(三)怎样理解 cosocket指令
- ngx_lua_API 指令详解(六)ngx.thread.spawn、ngx.thread.wait、ngx.thread.kill介绍
- ngx_lua 模块提供的指令和API等
- ngx_lua 模块API说明
- 【精选】Nginx模块Lua-Nginx-Module学习笔记(一)Nginx Lua API 接口详解
- ngx_lua模块API 浅析
- 【精选】Nginx模块Lua-Nginx-Module学习笔记(二)Lua指令详解(Directives)
- ngx_lua模块中的共享内存字典项API
- ngx_lua模块中的共享内存字典项API
- ngx_lua模块中的共享内存字典项API
- ngx_lua 模块API说明
- ngx_lua模块api
- ngx_lua模块中的共享内存字典项API
- ngx_lua模块中正则表达式相关的api
- JavaMail(JAVA邮件服务) API详解
- 配置openresty使用lua并发请求API
- Android EditText 详解Android2.2 API 中文文档系列(2) —— EditText