使用到的模块:lua-nginx-module
ngx_lua_module 是一个nginx http模块,它把 lua 解析器内嵌到 nginx,用来解析并执行lua 语言编写的网页后台脚本
安装lua-nginx-module
1.下载安装LuaJIT 2.1(2.0或者2.1都是支持的,官方推荐2.1):
http://luajit.org/download.html
cd /usr/local/src
wget http://luajit.org/download/LuaJIT-2.1.0-beta2.tar.gz
tar zxf LuaJIT-2.1.0-beta2.tar.gz
cd LuaJIT-2.1.0-beta2
make PREFIX=/usr/local/luajit
make install PREFIX=/usr/local/luajit
2.下载ngx_devel_kit(NDK)模块 :
https://github.com/simpl/ngx_devel_kit/tags,不需要安装
cd /usr/local/src
wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz
tar -xzvf v0.2.19.tar.gz
3.下载最新的lua-nginx-module 模块 :
https://github.com/openresty/lua-nginx-module/tags,不需要安装
cd /usr/local/src
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.2.tar.gz
tar -xzvf v0.10.2.tar.gz
4.nginx -V查看已经编译的配置
nginx -V
6.设置环境变量
export LUAJIT_LIB=/usr/local/luajit/lib && export LUAJIT_INC=/usr/local/luajit/include/luajit-2.1
7.在原有nginx上添加模块:
./configure --prefix=/usr/local/nginx --with-pcre --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-ipv6 --with-http_realip_module --with-pcre-jit --with-ld-opt='-ljemalloc' --with-ld-opt="-Wl,-rpath,/usr/local/luajit/lib" --add-module=/usr/local/src/lua-nginx-module-0.10.2/ --add-module=/usr/local/src/nginx-module-vts/
8.编译
make -j2
9.替换nginx二进制文件
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
cp -r ./objs/nginx /usr/local/nginx/sbin/
/usr/local/nginx/sbin/nginx -V
...
...
configure arguments: --prefix=/usr/local/nginx --with-pcre --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-ipv6 --with-http_realip_module --with-pcre-jit --with-ld-opt=-ljemalloc --with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib --add-module=/usr/local/src/lua-nginx-module-0.10.2/ --add-module=/usr/local/src/nginx-module-vts/
10.重启nginx生效
pkill -9 nginx
/usr/local/nginx/sbin/nginx
11.配置nginx.conf 实验lua模块是否安装成功
...
location /hello_lua {
default_type 'text/plain';
content_by_lua 'ngx.say("hello, lua")';
}
...
/usr/local/nginx/sbin/nginx -s reload
12.访问ip/hello_lua
|
请发表评论