17. Nginx and development of Lua

Installation and Lua Lua for nginx

#安装lua
yum install -y lua
lua -v

More efficient installation Lua interpreter LuaJIT

wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz
tar -zxvf LuaJIT-2.0.2.tar.gz
cd LuaJIT-2.0.2
make install PREFIX=/usr/local/LuaJIT/2.0.2
export LUAJIT_LIB=/usr/local/LuaJIT/2.0.2/lib
export LUAJIT_INC=/usr/local/LuaJIT/2.0.2/include/luajit-2.0
echo "/usr/local/LuaJIT/2.0.2/lib" >> /etc/ld.so.conf
ldconfig

Installation ngx_devel_kit lua-nginx-module and

wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc7.tar.gz
tar -zxvf v0.10.9rc7.tar.gz
tar -zxvf v0.3.0.tar.gz

#先make clean,然后在原有的nginx ./configure基础上,添加新的模块
#如果出现undefined reference to `X509_check_host'错误,需要添加--with-openssl选项,指向openssl 1.0.2安装包源码所在的目录。
./configure --add-module=/path/to/ngx_devel_kit-0.3.0 --add-module=/path/to/lua-nginx-module-0.10.9rc7
--with-openssl=/path/to/openssl-1.0.2k
make && make install

Use nginx log output request or response data

https://www.hardill.me.uk/wordpress/2018/03/14/logging-requests-and-response-with-nginx/

Nginx call lua

instruction Explanation
set_by_lua, set_by_lua_file Nginx variable settings
access_by_llua, access_by_lua_file Access control
content_by_lua, content_by_lua_file Receiving a request, in response to the output

Lua calls Nginx

variable Explanation
ngx.var nginx variables
ngx.req.get_headers Acquisition request header
ngx.req.get_uri_args Get request parameters
ngx.redirect Redirect
ngx.print Output content
ngx.say With ngx.print, it will be one more line breaks
ngx.header Output response header
... ...

Read topics

Guess you like

Origin www.cnblogs.com/zy108830/p/12600385.html