Nginx整合Lua步骤

1 篇文章 0 订阅
1 篇文章 0 订阅

1、Nginx:

yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

wget -c https://nginx.org/download/nginx-1.10.1.tar.gz

tar -xzf nginx-1.10.1.tar.gz

2.下载安装LuaJIT-2.0.4.tar.gz

wget -c http://luajit.org/download/LuaJIT-2.0.4.tar.gz
tar -zxf LuaJIT-2.0.4.tar.gz
cd LuaJIT-2.0.4

make install PREFIX=/usr/local/luajit

环境变量/etc/profile文件中增加环境变量,并执行source /etc/profile

export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
export LD_LIBRARY_PATH=/usr/local/luajit/lib:$LD_LIBRARY_PATH

3.下载解压ngx_devel_kit

wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
tar -xzf v0.3.0.tar.gz

4.下载解压lua-nginx-module

wget https://github.com/openresty/lua-nginx-module/archive/v0.10.8.tar.gz
tar -xzf v0.10.8.tar.gz

5、Nginx解压包下

./configure --add-module=/usr/local/ngx_devel_kit-0.3.0 --add-module=/usr/local/lua-nginx-module-0.10.8
make -j2
make install

将nginx做成命令  ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
启动:nginx  重启:nginx -s reload  关闭:nginx -s stop

错误1:
nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or

directory

解决:
环境变量/etc/profile文件中增加环境变量,并执行source /etc/profile

export LD_LIBRARY_PATH=/usr/local/luajit/lib:$LD_LIBRARY_PATH

错误2:
nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed (2: No such file or directory)

解决:
进入nginx安装目录下,使用nginx -c的参数指定nginx.conf文件的位置

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

测试:

        #直接写nginx-lua脚本语言方式
        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安装目录conf下
        }

        #test.lua中的内容
        ngx.say("hello, world")
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZhiYuanYe

您的鼓励将是我的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值