安裝 Lua 和 Lua for nginx
#安裝lua
yum install -y lua
lua -v
安裝更高效的 Lua 語言解釋器 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
安裝 ngx_devel_kit 和 lua-nginx-module
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
使用nginx日誌輸出 request 或 response 數據
https://www.hardill.me.uk/wor...
Nginx調用lua
指令 |
說明 |
set_by_lua, set_by_lua_file |
設置Nginx變量 |
access_by_llua, access_by_lua_file |
訪問控制 |
content_by_lua, content_by_lua_file |
接收請求,輸出響應 |
Lua調用Nginx
變量 |
說明 |
ngx.var |
nginx變量 |
ngx.req.get_headers |
獲取請求頭 |
ngx.req.get_uri_args |
獲取請求參數 |
ngx.redirect |
重定向 |
ngx.print |
輸出內容 |
ngx.say |
同ngx.print,會多一個換行符 |
ngx.header |
輸出響應頭 |
... |
... |
專題閱讀