nginx + nginx-lua模块安装(centos7.3)
1 下载安装LuaJIT
[root@localhost mysql3306]# cd /usr/local/src
[root@localhost src]# wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz
[root@localhost src]# tar -xvf LuaJIT-2.0.5.tar.gz
[root@localhost src]# cd LuaJIT-2.0.5
[root@localhost LuaJIT-2.0.5]# make
[root@localhost LuaJIT-2.0.5]# make install
2 下载nginx lua模块
[root@localhost src]# wget https://github.com/openresty/lua-nginx-module/archive/v0.10.10.tar.gz
[root@localhost src]# tar -xvf v0.10.10.tar.gz
3 下载nginx 模块
[root@localhost src]# wget http://nginx.org/download/nginx-1.13.5.tar.gz
[root@localhost src]# tar -xvf nginx-1.13.5.tar.gz
3 安装nginx、nginx-lua 模块
[root@localhost src]# export LUAJIT_LIB=/usr/local/lib
[root@localhost src]# export LUAJIT_INC=/usr/local/include/luajit-2.0
[root@localhost src]# cd nginx-1.13.5
编译nginx依赖zlib,pcre
安装zlib,pcre
[root@localhost nginx-1.13.5]# yum -y install pcre-devel openssl openssl-devel
[root@localhost nginx-1.13.5]# yum install zlib-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package zlib-devel-1.2.7-17.el7.x86_64 already installed and latest version
Nothing to do
[root@localhost nginx-1.13.5]# ./configure --prefix=/usr/local/nginx-1.13.5 --add-module=../lua-nginx-module-0.10.10/
[root@localhost nginx-1.13.5]# make
[root@localhost nginx-1.13.5]# make install
4 查看nginx
如果出现libluajit-5.1.so.2的错误
[root@localhost conf]# /usr/local/nginx-1.13.5/sbin/nginx -v
/usr/local/nginx-1.13.5/sbin/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
解决方法
[root@localhost conf]# ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
[root@localhost conf]# /usr/local/nginx-1.13.5/sbin/nginx -v
nginx version: nginx/1.13.5
5 nginx lua 配置
nginx配置文件加入如下配置
location ~* ^/aa/{
default_type 'text/plain';
content_by_lua 'ngx.say("aaaa")
local res = ngx.location.capture("/proxy/http/www.baidu.com/80/EmployeeLeasing/us/user/checkUserLogin.do", {
method = ngx.HTTP_POST,
body = body,
args = {hello = "world"}
})
for key,val in pairs(res) do
if type(val) == "table" then
ngx.say(key,"=>",table.concat(val,","))
else
ngx.say(key,"=>",val)
end
end';
}
location /proxy/ {
internal;
rewrite ^/proxy/(http?)/([^/]+)/(\d+)/(.*) /$4 break;
proxy_pass $1://$2:$3;
}
5 nginx lua 测试
5.1 启动nginx
[root@localhost conf]# /usr/local/nginx-1.13.5/sbin/nginx
5.2 访问测试
# curl http://localhost/aa/
评论 (2)