关于nginx nginx lua 的一些纪录
souces:
LuaJIT : http://luajit.org/download.html Nginx : http://nginx.org/en/download.html nginx_devel_kit : https://github.com/simpl/ngx_devel_kit/tags ngx_lua : https://github.com/openresty/lua-nginx-module/tags
install
shell> wget http://luajit.org/download/LuaJIT-<VERSION>.tar.gz
shell> tar zxvf LuaJIT-<VERSION>.tar.gz
shell> cd LuaJIT-<VERSION>
shell> make
shell> make install
因为安装在缺省路径,所以LuaJIT对应的lib,include均在/usr/local目录里。
shell> export LUAJIT_LIB=/usr/local/lib
shell> export LD_LIBRARY_PATH=/usr/local/luajit/lib/:$LD_LIBRARY_PATH
shell> export LUAJIT_INC=/usr/local/include/luajit-<VERSION>
顺手加export 到 root 的 .bash_profile 里面
vim ~/.bash_profile
export LUAJIT_LIB=/usr/local/luajit/lib
export LD_LIBRARY_PATH=/usr/local/luajit/lib/:$LD_LIBRARY_PATH
export LUAJIT_INC=/usr/local/include/luajit-2.0
编译Nginx
shell> wget http://nginx.org/download/nginx-<VERSION>.tar.gz
shell> tar zxvf nginx-<VERSION>.tar.gz
shell> cd nginx-<VERSION>
shell> ./configure
--add-module=/path/to/ngx_lua \
--add-module=/path/to/ngx_devel_kit
shell> make
shell> make install
试着启动一下Nginx看看,如果你运气不好的话,可能会遇到如下错误:
cannot open shared object file: No such file or directory
这是神马情况?可以用ldd命令来看看:
shell> ldd /path/to/nginx
libluajit-<VERSION>.so => not found
此类问题通常使用ldconfig命令就能解决:
shell> echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
shell> ldconfig
nginx configs
location /lua {
set $test "hello, world.";
content_by_lua '
ngx.header.content_type = "text/plain";
ngx.say(ngx.var.test);
';
}
sources
[lamp notes] : http://huoding.com/2012/08/31/156