获取请求参数
vim /usr/example/example.conf
location /lua_var {
default_type 'text/plain';
content_by_lua_block {
ngx.say(ngx.var.arg_a)
}
}
重新加载nginx配置文件: nginx -s reload
在浏览器上访问http://116.196.177.123/lua_var?a=323,浏览器显示:
323
在上述代码中,涉及到了2个api, 一是ngx.say(直接返回请求结果);二是ngx.var,它是获取请求的参数,比如本例子上的?a=323,获取之后,直接输出为请求结果。
获取请求类型
vim /usr/example/example.conf
location /lua_request{
default_type 'text/html';
lua_code_cache off;
content_by_lua_file /usr/example/lua/lua_request.lua;
}