nginx1.8+ngx_lua模块安装测试
1、安装说明
系统版本:CentOS release 6.5 (Final)
测试地址:192.168.1.27
2、下载安装LuaJIT
下载最新版安装包:
cd /usr/local/src
wget https://luajit.org/download/LuaJIT-2.0.4.tar.gz
tar -xzvf LuaJIT-2.0.4.tar.gz
cd LuaJIT-2.0.4
make
如果出现下面,说明编译成功,可以继续
OK Successfully built LuaJIT
make[1]: Leaving directory `/usr/local/src/LuaJIT-2.0.4/src'
==== Successfully built LuaJIT 2.0.4 ====
然后执行
make install
出现如下内容,说明安装成功
ln -sf luajit-2.0.4 /usr/local/bin/luajit
==== Successfully installed LuaJIT 2.0.4 to /usr/local ====
3、下载ngx_devel_kit 模块
cd /usr/local/src
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
tar zxvf v0.3.0.tar.gz
注:最新版地址可到 https://github.com/simpl/ngx_devel_kit/tags
4、下载准备lua-nginx-module 模块
cd /usr/local/src
wget https://github.com/chaoslawful/lua-nginx-module/archive/v0.10.5.tar.gz
tar -xzvf v0.10.5.tar.gz
注:最新版本获取地址 https://github.com/openresty/lua-nginx-module/releases
5、安装nginx+ngx_lua
groupadd www
useradd -g www www -s /bin/false
安装zlib模块(1.2.8)
wget https://zlib.net/zlib-1.2.8.tar.gz
tar zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make && make install
安装prce 作用 重写rewrite
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
tar -zxvf pcre-8.36.tar.gz
cd pcre-8.36
./configure
make
make install
ln -s /usr/local/lib/libpcre.so.1 /lib64/
ln -s /usr/local/lib/libpcre.so.1 /lib/
ln -s /usr/local/lib/libpcre.so.1 /usr/local/lib64/
安装openssl ssl 功能需要 openssl 库
wget ftp://ftp.openssl.org/source/openssl-1.0.2c.tar.gz
tar zxvf openssl-1.0.2c.tar.gz
cd openssl-1.0.2c
./config(注意)
make
make install
安装nginx1.8.0+ngx_lua模块
cd /usr/local/src
tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-pcre=../pcre-8.36 --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-1.0.2c --with-http_gzip_static_module --add-module=../lua-nginx-module-0.10.5 --add-module=/usr/local/src/ngx_devel_kit-0.3.0/
make
make install
启动 nginx
# /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
解决方法:
# ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
查看nginx安装的模块参数
# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.8.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
built with OpenSSL 1.0.2c 12 Jun 2015
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-pcre=../pcre-8.36 --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-1.0.2c --with-http_gzip_static_module --add-module=../lua-nginx-module-0.10.5 --add-module=/usr/local/src/ngx_devel_kit-0.3.0/
注意,如果这里是升级安装的话,就是之前已经安装过nginx了,现在要新增ngx_lua模块
先查看 nginx安装了哪些模块
/usr/local/nginx/sbin/nginx -V
然后在重新编译
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-pcre=../pcre-8.36 --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-1.0.2c --with-http_gzip_static_module --add-module=../lua-nginx-module-0.10.5 --add-module=/usr/local/src/ngx_devel_kit-0.3.0/
然后make后,不要make install ,否则会覆盖之前安装的文件
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_bak
cp ./nginx /usr/local/nginx/sbin/nginx
然后启动nginx
6、测试安装
编辑/usr/local/nginx/conf/nginx.conf
location /lua {
set $test "hello, world.";
content_by_lua '
ngx.header.content_type = "text/plain";
ngx.say(ngx.var.test);
';
}
重新加载ngInx配置文件
/usr/local/nginx/sbin/nginx -s reload
访问https://192.168.1.27/lua
评论