记录下LNMP平滑升级Nginx并安装ngx_lua模块教程,希望对大家有所帮助。
#ngx_lua module项目地址 https://github.com/chaoslawful/lua-nginx-module 在LNMP安装包后,重编译nginx,并添加ngx_lua模块
1」Download
wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz wget https://github.com/chaoslawful/lua-nginx-module/archive/v0.9.16.tar.gz wget http://nginx.org/download/nginx-1.9.2.tar.gz
2」安装LuaJIT
tar -zxvf LuaJIT-2.0.4.tar.gz cd LuaJIT-2.0.4 make make install export LUAJIT_LIB=/usr/local/lib export LUAJIT_INC=/usr/local/include/luajit-2.0
3」copy模块
cp v0.2.19.tar.gz /usr/local/src cp v0.9.16.tar.gz /usr/local/src tar -zxvf v0.2.19.tar.gz tar -zxvf v0.9.16.tar.gz 解压下载下来的ngx_devel_kit以及lua-nginx-module到/usr/local/src目录下,即 /usr/local/src/lua-nginx-module-0.9.16/ /usr/local/src/ngx_devel_kit-0.2.19/
3」重新编译Nginx
tar -zxvf nginx-1.9.2.tar.gz 解压nginx包,configure一下(参考LNMP安装包,未加其他修改) ./configure --user=www --group=www --prefix=/usr/local/nginx --with-ld-opt="-Wl,-rpath,$LUAJIT_LIB" --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --add-module=/usr/local/src/lua-nginx-module-0.9.16/ --add-module=/usr/local/src/ngx_devel_kit-0.2.19/ OK后make,别make install,否则就覆盖安装
4」备份替换
make完后在objs目录下多了个nginx,即新版本的程序 备份旧的nginx程序 cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
新nginx程序覆盖旧的 cp objs/nginx /usr/local/nginx/sbin/nginx
如果提示“cp:cannot create regular file `/usr/local/nginx/sbin/nginx': Text file busy” 建议使用如下语句cp cp -rfp objs/nginx /usr/local/nginx/sbin/nginx
测试新的nginx程序是否正确 /usr/local/nginx/sbin/nginx -t nginx: theconfiguration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx:configuration file /usr/local/nginx/conf/nginx.conf test issuccessful
平滑重启nginx /usr/local/nginx/sbin/nginx -s reload
查看ngixn版本及其编译参数 /usr/local/nginx/sbin/nginx -V
「问题解决」1.如遇到找不到库文件echo “/usr/local/lib” > /etc/ld.so.conf.d/usr_local_lib.confldconfig即可2./usr/local/nginx/sbin/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory 在 Nginx 编译时,需要指定 RPATH,记得加入下面选项:./configure --with-ld-opt="-Wl,-rpath,
需要luafilesystem 的可以参考以下 为nginx的luajit安装luarocks并安装luafilesystem
题有点绕口。我尽量把关键词都贴进去。之前因为自己的nginx安装了ngx_lua模块,但是又需要引入
但是安装luafilesystem又需要先安装luarocks,比较繁琐。这里就想记录一下安装过程。
下面进入正题
下载:
wget http://keplerproject.github.io/luarocks/releases/luarocks-2.2.2.tar.gz
解压:
tar -zxvf luarocks-2.2.2.tar.gz
进入目录:
cd luarocks-2.2.2
安装 luarocks
./configure --with-lua="/usr/local" --lua-suffix="jit" --with-lua-include="/usr/local/include/luajit-2.0"
其中“/usr/local/include/luajit-2.0” 可以 find / -name lua.h 先找下路径
make build
make install
安装 luafilesystem
luarocks install luafilesystem