nginx 1.4.2 lua

2013-08-25 22:09:19 0  category: nginx

nginx lua

nginx 安装 lua


0.下载需要的软件


[root@q_cent ~]#  wget http://nginx.org/download/nginx-1.4.2.tar.gz
[root@q_cent ~]# wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz
[root@q_cent ~]# wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.18.tar.gz
[root@q_cent ~]# mv v0.2.18 ngx_devel_kit.tar.gz
[root@q_cent ~]# wget https://github.com/chaoslawful/lua-nginx-module/archive/v0.8.6.tar.gz
[root@q_cent ~]# mv v0.8.6.tar.gz lua-nginx-module.0.8.6.tar.gz


[root@q_cent ~]# tar xvf nginx-1.4.2.tar.gz
[root@q_cent ~]# tar xvf LuaJIT-2.0.2.tar.gz
[root@q_cent ~]# tar xvf ngx_devel_kit.tar.gz
[root@q_cent ~]# tar xvf lua-nginx-module.0.8.6.tar.gz




1.安装 LuaJit2.0 (推荐) 或安装 Lua 5.1 ( Lua 5.2 现在不支持 ).



[root@q_cent ~]#  cd LuaJIT-2.0.2
[root@q_cent LuaJIT-2.0.2]# make PREFIX=/usr/local/luajit
[root@q_cent LuaJIT-2.0.2]# make install PREFIX=/usr/local/luajit


2.设定 LUAJIT_LIB  LUAJIT_INC 变量


[root@q_cent LuaJIT-2.0.2]# export LUAJIT_LIB=/usr/local/luajit/lib
[root@q_cent LuaJIT-2.0.2]# export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0

// 如果用的是 tcsh csh

[root@q_cent LuaJIT-2.0.2]# setenv LUAJIT_LIB /usr/local/luajit/lib
[root@q_cent LuaJIT-2.0.2]# setenv LUAJIT_INC /usr/local/luajit/include/luajit-2.0



3. 安装 nginx 并添加 lua 模块


[root@q_cent LuaJIT-2.0.2]# cd /root/nginx-1.4.2

[root@q_cent nginx-1.4.2]# ./configure --prefix=/usr/local/nginx142 --add-module=/root/ngx_devel_kit-0.2.18/ --add-module=/root/lua-nginx-module-0.8.6 --without-http_scgi_module --without-http_ssi_module --without-http_uwsgi_module --with-http_ssl_module

[root@q_cent nginx-1.4.2]# make && make install


4. 如果 nginx 启动遇到错误


[root@qcent6 nginx142]# ldd  sbin/nginx
[root@qcent6 nginx142]# echo "/usr/local/luajit/lib" >> /etc/ld.so.conf.d/usr_local_lib.conf

[root@qcent6 nginx142]# ldconfig



5. 添加下面的代码到 nginx.conf 并重启Nginx

location /lua {
set $test "hello, xlxz.org.";
content_by_lua '
ngx.header.content_type = "text/html";
ngx.say(ngx.var.test);
';
}


官方手册 http://wiki.nginx.org/HttpLuaModule

推荐文章