Nginx+lua编译安装
一、安装准备
源码选定目录
/root/sources
1.安装openssl、pcre、zlib库
openssl下载地址:https://www.openssl.org/source/
pcre下载:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
zlib下载:http://zlib.net/
2.安装必要的程序包
#yum -y install openssl-devel pcre-devel zlib-devel
3.安装openssl:
#cd /root/sources
#tar xf openssl-1.0.2j.tar.gz -C /usr/local/src/
#cd /usr/local/src
#ln -sv openssl-1.0.2 openssl
#cd openssl
#./config --prefix=/usr/local/openssl && make && make install
#/usr/local/openssl/bin/openssl version
4.安装pcre:
#cd /root/sources
#tar xf pcre-8.39.tar.gz -C /usr/local/src/
#cd /usr/local/src/
#ln -sv pcre-8.39 pcre
#cd pcre
#./configure --prefix=/usr/local/pcre --enable-shared && make &&make install
5.安装zlib库:
#cd /root/sources/
#tar xf zlib-1.2.11.tar.gz -C /usr/local/src/
#cd /usr/local/src
#ln -sv zlib-1.2.11
#cd zlib
#./configure --prefix=/usr/local/zlib && make && make install
二、编译安装nginx+lua
1.下载安装LuaJIT
下载地址:http://luajit.org/download.html
#cd /root/sources
#tar xf LuaJIT-2.0.2.tar.gz -C /usr/local/src
#cd /usr/local/src/LuaJIT-2.0.2/
#make
出现如下内容表示编译成功
OK Successfully built LuaJIT
make[1]:Leaving directory `/usr/local/src/LuaJIT-2.0.2/src'
====Successfully built LuaJIT 2.0.2 ====
#make install
出现如下内容,表示安装成功
====Successfully installed LuaJIT 2.0.2 to /usr/local ====
配置LuaJIT,让nginx知道要到哪里去找luajit
#exportLUAJIT_LIB=/usr/local/lib
#exportLUAJIT_INC=/usr/local/include/luajit-2.0
2.下载ngx_devel_kit(不需要安装)
下载地址:https://github.com/simpl/ngx_devel_kit/tags
#cd /root/sources
#tar xf ngx_devel_kit-0.2.19.tar.gz -C /usr/local/src/
#cd /usr/local/src
#ln -sv ngx_devel_kit-0.2.19/ ngx_devel_kit
3.下载lua-nginx-module(不需要安装)
下载地址:https://github.com/openresty/lua-nginx-module/tags
#cd /root/sources
#tar xf lua-nginx-module-0.10.0.tar.gz -C /usr/local/src/
#cd /usr/local/src/
#ln -sv lua-nginx-module-0.10.0/ lua-nginx-module
4.编译安装nginx+lua
源码包可从nginx官网获取:nginx.org
#groupadd -r nginx
#useradd -g nginx -M -s /sbin/nologin nginx
#cd /root/sources
#tar xf nginx-1.8.1.tar.gz -C /usr/local/src/
#cd /usr/local/src/
# ln -sv nginx-1.8.1/ nginx
#cd nginx
#./configure--user=nginx --group=nginx --prefix=/usr/local/nginx--conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid--lock-path=/var/lock/subsys/nginx --error-log-path=/var/log/nginx/error_log--http-log-path=/var/log/nginx/access_log --with-http_ssl_module--with-http_dav_module --with-http_realip_module --with-http_stub_status_module--with-http_gzip_static_module --with-threads --with-http_addition_module--with-pcre=/usr/local/src/pcre --with-zlib=/usr/local/src/zlib --with-openssl=/usr/local/src/openssl--add-module=/usr/local/src/ngx_devel_kit--add-module=/usr/local/src/lua-nginx-module
注意:openssl、pcre、zlib指定的是源码目录而不是安装目录
#make
#make install (如果是首次安装nginx需要进行make install,如果是为nginx增加相关功能模块,则不需要执行make install,不然会覆盖以前的nginx编译信息)
如果是为nginx增加相关功能,则需要替换nginx二进制文件,先备份一下原来的启动脚本
#cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
需要把nginx进程杀掉,不然复制会报错
#killall nginx
#cd /usr/local/src/nginx
#cp ./objs/nginx /usr/local/nginx/sbin
cp:overwrite `/usr/local/nginx/sbin/nginx’? yes
5.此时查看下nginx所有的模块
#/usr/local/nginx/sbin/nginx -V
sbin/nginx: error while loading sharedlibraries: libluajit-5.1.so.2: cannot open shared object file: No such file ordirectory
出现以上报错解决方法
#ln -sv /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
6.在配置文件中添加以下配置并测试
location ~* ^/2328(/.*) {
default_type 'text/plain';
content_by_lua 'ngx.say("hello, ttlsa lua")';
}
curl http://192.168.56.62/2328/
hello,ttlsa lua #测试成功