Nginx安装lua支持
需要LuaJIT-2.0.4.tar.gz,ngx_devel_kit,lua-nginx-module
1.下载安装LuaJIT-2.0.4.tar.gz
#安装环境
yum install gcc gcc-c++ make wget vim bzip2 -y
wget -c http://luajit.org/download/LuaJIT-2.0.4.tar.gz
tar xzvf LuaJIT-2.0.4.tar.gz
cd LuaJIT-2.0.4
make install PREFIX=/usr/local/luajit
#注意环境变量!
vim /etc/bashrc
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
#加载环境变量
source /etc/bashrc
2.下载解压ngx_devel_kit
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
tar -xzvf v0.3.0.tar.gz -C /usr/local/src
3.下载解压lua-nginx-module
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.8.tar.gz
tar -xzvf v0.10.8.tar.gz -C /usr/local/src
4.下载安装nginx-1.10.3.tar.gz
wget https://openssl.org/source/openssl-1.0.2p.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.bz2
wget http://zlib.net/zlib-1.2.11.tar.gz
wget http://nginx.org/download/nginx-1.10.3.tar.gz
#解压缩到/usr/local/src下
tar zxvf openssl-1.0.2p.tar.gz -C /usr/local/src/
tar jxvf pcre-8.42.tar.bz2 -C /usr/local/src/
tar zxvf zlib-1.2.11.tar.gz -C /usr/local/src/
tar -xzvf nginx-1.10.3.tar.gz -C /usr/local/src
cd nginx-1.10.3
./configure --prefix=/usr/local/nginx10 --add-module=/usr/local/src/ngx_devel_kit-0.3.0 --add-module=/usr/local/src/lua-nginx-module-0.10.8 --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.42 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.0.2p --with-http_stub_status_module --without-http-cache --with-http_gzip_static_module
#注意ngx_devel_kit和lua-nginx-module以实际解压路径为准
make -j2
make install
5.验证
#将nginx做成命令
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
cd /usr/local/nginx/conf/
vi nginx.conf
#lua指令方式
#在server 中添加一个localtion
location /hello {
default_type 'text/plain';
content_by_lua 'ngx.say("hello, lua")';
}
#lua文件方式
#在server 中添加一个localtion
location /lua {
default_type 'text/html';
content_by_lua_file conf/lua/test.lua; #相对于nginx安装目录
}
#test.lua文件内容
ngx.say("hello world");
#启动nginx(已经做了软连接了,可以在任何目录启动)
nginx
注:
报错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/luajit/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
具体source的路径已实际安装路径为准
访问:
http://127.0.0.1/hello
显示:hello, lua
http://127.0.0.1/lua
显示:hello world
到这里确定安装成功。
网友评论