Nginx添加Lua模块

第一步:安装LuaJIT
wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz
tar zxvf LuaJIT-2.0.2.tar.gz 
make && make install PREFIX=/usr/local/lua
echo "/usr/local/lua/lib" > /etc/ld.so.conf.d/luajit.conf
第二步:下载Ngx_lua模块
wget -O ngx_devel_kit0.2.19.tar.gz https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz
tar zxvf ngx_devel_kit0.2.19.tar.gz
wget -O lua-nginx0.9.4.tar.gz https://github.com/chaoslawful/lua-nginx-module/archive/v0.9.4.tar.gz
tar zxvf lua-nginx0.9.4.tar.gz
export LUAJIT_LIB=/usr/local/lua/lib/
export LUAJIT_INC=/usr/local/lua/include/luajit-2.0/
第三步:添加Ngx_lua模块
./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=../ngx_devel_kit-0.2.19/ --add-module=../lua-nginx-module-0.9.4/
make
/etc/init.d/nginx stop
cp objs/nginx /usr/local/nginx/sbin/nginx
/etc/init.d/nginx start
第四步:修改ngx配置
location ~ /lua {
  default_type 'text/plain';
  content_by_lua 'ngx.say("hello, lua!")';
}
/etc/init.d/nginx start
在浏览器中查看效果: http://127.0.0.1/lua/ 输出 hello,lua!

你可能感兴趣的:(lua)