nginx安装,nginx-lua模块安装(centos7.3)

nginx安装,nginx-lua,echo模块安装


1 下载安装LuaJIT

[root@iZuf6679bcuj0vciz1vaicZ mysql3306]# cd /usr/local/src
[root@iZuf6679bcuj0vciz1vaicZ src]# wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz
[root@iZuf6679bcuj0vciz1vaicZ src]# tar -xvf LuaJIT-2.0.5.tar.gz
[root@iZuf6679bcuj0vciz1vaicZ src]# cd LuaJIT-2.0.5

[root@iZuf6679bcuj0vciz1vaicZ LuaJIT-2.0.5]# make
[root@iZuf6679bcuj0vciz1vaicZ LuaJIT-2.0.5]# make install


2 下载nginx lua模块


[root@iZuf6679bcuj0vciz1vaicZ src]# wget https://github.com/openresty/lua-nginx-module/archive/v0.10.10.tar.gz
[root@iZuf6679bcuj0vciz1vaicZ src]# tar -xvf v0.10.10.tar.gz 

3 下载nginx 模块


[root@iZuf6679bcuj0vciz1vaicZ src]# wget http://nginx.org/download/nginx-1.13.5.tar.gz
[root@iZuf6679bcuj0vciz1vaicZ src]# tar -xvf nginx-1.13.5.tar.gz 

3 安装nginx、nginx-lua 模块

[root@iZuf6679bcuj0vciz1vaicZ src]# export LUAJIT_LIB=/usr/local/lib
[root@iZuf6679bcuj0vciz1vaicZ src]# export LUAJIT_INC=/usr/local/include/luajit-2.0
[root@iZuf6679bcuj0vciz1vaicZ src]# cd nginx-1.13.5

编译nginx依赖zlib,pcre
安装zlib,pcre
[root@iZuf6679bcuj0vciz1vaicZ nginx-1.13.5]# yum -y install pcre-devel openssl openssl-devel
[root@iZuf6679bcuj0vciz1vaicZ 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@iZuf6679bcuj0vciz1vaicZ nginx-1.13.5]# ./configure --prefix=/usr/local/nginx-1.13.5 --add-module=../lua-nginx-module-0.10.10/
[root@iZuf6679bcuj0vciz1vaicZ nginx-1.13.5]# make
[root@iZuf6679bcuj0vciz1vaicZ nginx-1.13.5]# make install

4 查看nginx

如果出现libluajit-5.1.so.2的错误
[root@iZuf6679bcuj0vciz1vaicZ 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@iZuf6679bcuj0vciz1vaicZ conf]# ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
[root@iZuf6679bcuj0vciz1vaicZ 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@iZuf6679bcuj0vciz1vaicZ conf]# /usr/local/nginx-1.13.5/sbin/nginx
5.2 访问测试

# curl http://localhost/aa/ 

你可能感兴趣的:(Nginx,nginx,nginx-lua)