nginx对lua脚本的支持

nginx 对lua模块得支持

模块语法lua指令:

set_by_lua 设置nginx变量 可以实现复杂赋值逻辑

set_by_lua_file 设置nginx变量 可以实现复杂赋值逻辑

access_by_lua 请求访问阶段处理。用于访问控制

access_by_lua_file 请求访问阶段处理。用户访问控制

content_by_lua 内容处理器。 处理接受和响应输出

content_by_lua_file 内容处理器。 处理接受和响应输出

nginx lua api

ngx.var nginx变量

ngx.req.get_headers 获取请求头

ngx.req.get_uri_args 获取url请求参数

ngx.redirect 重定向

ngx.print 输出响应内容体

ngx.say 和 ngx.print一样,但最后会输出一个换行符

ngnx.header 输出响应头

 

1. 直接执行个lua脚本命令

 在nginx.conf里加:

location /lua{

  default_type "text/html";

  content_by_lua 'ngx.say("hello world")';

}

访问对应路径即可在页面输出hello world

 

2.写个lua脚本执行

1)创建/usr/local/openresty/lua/hellolua.lua脚本并写ngx.say(hello world)

2) 在nginx.conf里加:

location /lua{
            default_type  "text/html";
            content_by_lua_file /usr/local/openresty/lua/hello.lua;
        }

 

posted @ 2020-08-02 08:46  neona  阅读(2412)  评论(0编辑  收藏  举报