Nginx、lua、openresty
Lua精简高效的特点加上Nginx的强大,可以包容到lua语言,读取nginx的各种环境变量。
开发nginx 的插件的时候不需要使用c语言了
openResty
基于nginx+lua开发的开源产品。将lua脚本整合到了nginx当中。
通过lua扩展nginx实现可伸缩的web平台。
openResty目录结构
lualib:lua相关源码
luajit:运行环境
nginx : 原有的目录内容
lua热部署配置
只能是外部lua文件才能热加载
server{lua_code_cache:off;}
nginx执行lua脚本的方法
直接在location中写lua脚本语句
location /lua{default_type text/html;content_by_lua 'ngx.say("<b>hello world!</b><br>hhh")';}
或者使用content_by_lua_block
location /lua{default_type text/html;content_by_lua_block {ngx.say("<b>hello world!</b><br>hhh")}}
加载lua脚本文件执行
conf目录下创建001.lua文件
location /lua{default_type text/html;content_by_lua_file conf/001.lua ;}
将所有lua配置都引用外部文件
新增lua.conf文件,conf目录里面添加content_by_lua_file
location /lua{default_type text/html;include lua.conf;}
或者,
include lua.conf; #在lua.conf中写location
lua获取参数
ngx.var
location /lua{default_type text/html;content_by_lua_block {ngx.say(ngx.var.arg_a) #其中的a就是传输的参数}}
取到所有的变量

获取请求头的信息
