ngx_lua module 模块安装

前两天遇到Nginx使用if语句导致Nginx逻辑混乱的问题,Mail给[email protected]。他推荐使用ngx_lua module 来处理较为复杂的逻辑,毕竟if is evil。

简述模块安装过程:

--------------------------------------------------------------------------------
##参考文档
--------------------------------------------------------------------------------
##项目地址

https://github.com/chaoslawful/lua-nginx-module
##Lua拓展nginx 参考文档
http://rhomobi.com/topics/112
##Nginx与Lua 参考文档
http://huoding.com/2012/08/31/156
##HttpLuaModule Nginx Wiki
http://wiki.nginx.org/HttpLuaModule

--------------------------------------------------------------------------------
##下载

--------------------------------------------------------------------------------
wget http://luajit.org/download/LuaJIT-2.0.2.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.1.tar.gz
wget http://nginx.org/download/nginx-1.4.3.tar.gz

--------------------------------------------------------------------------------
##首先安装LuaJIT

-------------------------------------------------------------------------------
##install LuaJIT

tar -zxvf LuaJIT-2.0.2.tar.gz
cd LuaJIT-2.0.2
./configure
make
make install
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0

--------------------------------------------------------------------------------
##安装Nginx

-------------------------------------------------------------------------------
##解压下载下来的ngx_devel_kit以及lua-nginx-module 到/usr/local/src
##install nginx 为方便调试,我添加了echo模块以及开启debug模式

./configure --user=www --group=www \
--prefix=/usr/local/nginx-1.4.3 \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_perl_module \
--with-pcre=/usr/local/src/pcre-8.12 \
--with-debug \
--add-module=/usr/local/src/lua-nginx-module-0.9.1/ \
--add-module=/usr/local/src/ngx_devel_kit-0.2.19/ \
--add-module=/usr/local/src/echo-nginx-module-0.49/

--------------------------------------------------------------------------------
#启动nginx
--------------------------------------------------------------------------------
错误处理:找不到库文件,处理方式如下。


echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
ldconfig
#重新启动
/usr/local/nginx-1.4.3/sbin/nginx

推荐阅读

相关推荐