nginx-lua搭建流程

Posted by Clear Blog on April 16, 2018

下载安装LuaJIT

(http://luajit.org/download.html)

1
2
3
4
5
6
7
cd /usr/local/src  
wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz 
tar zxf LuaJIT-2.0.5.tar.gz 
cd LuaJIT-2.0.5
make PREFIX=/usr/local/luajit 
make install PREFIX=/Users/clear/software/  
luajit

下载ngx_devel_kit(NDK)

https://github.com/simpl/ngx_devel_kit/tags

1
2
3
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

下载最新的lua-nginx-module 模块

(https://github.com/openresty/lua-nginx-module/tags)

1
2
3
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

nginx -V查看已经编译的配置

nginx -V

进入之前安装nginx的解压目录,重新编译安装(在nginx -V得到的配置下,加入ngx_devel_kit-0.2.19和ua-nginx-module-0.10.2的目录),最终的配置如下: 设置环境变量

1
2
3
4
5
6
7
8
export LUAJIT_LIB=/Users/clear/software/luajit/lib
export LUAJIT_INC=/Users/clear/software/luajit/include/luajit-2.0
./configure --prefix=/Users/clear/software/nginx --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-openssl=/Users/clear/software/openssl-1.0.2n --with-pcre=/Users/clear/software/pcre-8.35 --with-pcre-jit --with-ld-opt='-ljemalloc' --with-ld-opt="-Wl,-rpath,/Users/clear/software/luajit/lib" --add-module=/Users/clear/software/ngx_devel_kit-0.3.1rc1 --add-module=/Users/clear/software/lua-nginx-module-0.10.12rc2

./configure --prefix=/Users/clear/software/nginx --with-http_stub_status_module --with-http_v2_module --with-openssl=/Users/clear/software/openssl-1.0.2n --with-pcre=/Users/clear/software/pcre-8.35 --with-pcre-jit --with-ld-opt="-Wl,-rpath,/Users/clear/software/luajit/lib" --add-module=/Users/clear/software/ngx_devel_kit-0.3.1rc1 --add-module=/Users/clear/software/lua-nginx-module-0.10.12rc2

make -j2
make install

查看是否编译成功

在/usr/local/nginx/conf/nginx.conf中加入如下代码:

location /hello_lua { default_type ‘text/plain’; content_by_lua ‘ngx.say(“hello, lua”)’; } 重启nginx: service nginx restart 访问10.211.55.3/hello_lua会出现”hello, lua”表示安装成功 hello, lua