版本说明:
linux: 1.8.1
luajit:2.0.2(不要使用标准lua,应当使用luajit, 后者的效率比前者高很多)
ngx_devel_kit: 0.2.18
lua-nginx-module: 0.9.8 (之前用了0.8.6版本,在编译nginx出现了一些方法变量未定义之类的问题)
必要软件包
http://luajit.org/download/LuaJIT-2.0.2.tar.gz
https://github.com/simpl/ngx_devel_kit/archive/v0.2.18.tar.gz
https://github.com/openresty/lua-nginx-module/archive/v0.9.8.tar.gz
luajit编译安装
make install PREFIX=/usr/local/luajit
nginx添加模块(无覆盖安装)
设置系统共享动态链接库
echo "/usr/local/luajit/lib" > /etc/ld.so.conf.d/usr_local_luajit_lib.conf
ldconfig
设置环境变量
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
在nginx安装目录下,配置添加两个模块
./configure --add-module=/opt/lua-tools/ngx_devel_kit-0.2.18 --add-module=/opt/lua-tools/lua-nginx-module-0.9.8
make
成功后,将nginx-1.8.1/objs目录下的nginx文件替换已安装的nginx执行文件(/usr/local/nginx/sbin)
检测lua配置nginx.conf
location = /test {
content_by_lua '
ngx.say("Hello World")
ngx.log(ngx.ERR, "err err err")
';
}