下载:http://luajit.org/download/LuaJIT-2.0.4.tar.gz
tar -zxvf LuaJIT-2.0.4.tar.gz
cd LuaJIT-2.0.4
make
make install
下载:https://github.com/simpl/ngx_devel_kit/archive/v0.3.0rc1.tar.gz
tar -zxvf v0.3.0rc1.tar.gz
mv ngx_devel_kit-0.3.0rc1 /data/apps/tools/
下载:https://github.com/openresty/lua-nginx-module/archive/v0.10.2.tar.gz
tar -zxvf v0.10.2.tar.gz
mv lua-nginx-module-0.10.2 /data/apps/tools/
下载:http://nginx.org/download/nginx-1.8.1.tar.gz
tar -zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-<VERSION>
./configure --prefix=/data/apps/nginx-1.8.1 --add-module=/data/apps/tools/ngx_devel_kit-0.3.0rc1 --add-module=/data/apps/tools/lua-nginx-module-0.10.2
make
make install
试着启动一下Nginx看看,可能会遇到如下错误:
nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
解决办法:
ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
到此基本安装就完了,如果lua中需要用到json,那么还需要安装cjson
下载:http://www.kyne.com.au/~mark/software/download/lua-cjson-2.1.0.tar.gz
tar -zxvf lua-cjson-2.1.0.tar.gz
cd lua-cjson-2.1.0
make
可能会出现如下错误
cc -c -O3 -Wall -pedantic -DNDEBUG -I/usr/local/include -fpic -o lua_cjson.o lua_cjson.c
lua_cjson.c:43:17: 致命错误:lua.h:没有那个文件或目录
#include <lua.h>
^
编译中断。
make: *** [lua_cjson.o] 错误 1
错误处理:
修改Makefile中的LUA_INCLUDE_DIR为如下:LUA_INCLUDE_DIR = $(PREFIX)/include/luajit-2.0
或
cp /usr/local/include/luajit-/* /usr/local/include/
编译完成之后会在目录下生成一个cjson.so
将这个文件拷贝到lua的package.cpath下
或者
nginx配置中修改:
lua_package_path '/usr/local/lib/lua/resty/?.lua;;';
lua_package_cpath '/usr/local/lib/lua/?.so;;';