在nginx中加入lua模块可以利用lua脚本的逻辑处理能力,轻松处理一些网络请求,提高效率。
1、首先安装LuaJIT 2.1,下载地址:http://luajit.org/download.html,解压后执行make安装即可,很简单。
make make install PREFIX=/opt/programs/luaJIT
2、使用export创建临时环境变量:
export LUAJIT_LIB=/opt/programs/luaJIT/lib export LUAJIT_INC=/opt/programs/luaJIT/include/luajit-2.1
3、下载ngx_devel_kit (NDK)模块:https://github.com/simplresty/ngx_devel_kit/tags,解压
4、下载ngx_lua模块:https://github.com/openresty/lua-nginx-module/tags,解压
5、编译nginx,目前兼容的nginx最新版是1.13.6,查看兼容性:https://github.com/openresty/lua-nginx-module#nginx-compatibility
./configure --prefix=/opt/programs/nginx --with-openssl=/opt/nginx_source/OpenSSL_1_1_1-pre2 --with-openssl-opt='enable-tls1_3 enable-ec_nistp_64_gcc_128 enable-weak-ssl-ciphers' --with-http_v2_module --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-ld-opt="-Wl,-rpath,/opt/programs/luaJIT/lib" --add-module=/opt/nginx_source/nginx-http-concat-1.2.2 --add-module=/opt/nginx_source/nginx_http_trim_filter_cn --add-module=/opt/nginx_source/luamodule/lua-nginx-module-0.10.13 --add-module=/opt/nginx_source/luamodule/ngx_devel_kit-0.3.1rc1
完成后,就是make了
make make install
参考:https://github.com/openresty/lua-nginx-module#installation