在nginx的基础上安装lua模块,实现nginx执行shell脚本

nginx安装可以参考 https://blog.csdn.net/ab7253957/article/details/85266493

如果没有安装过nginx可以使用openresty,是对nginx的增强

1.下载安装LuaJIT 2.1 http://luajit.org/download.html

wget http://luajit.org/download/LuaJIT-2.1.0-beta2.tar.gz
tar -zxvf LuaJIT-2.1.0-beta2.tar.gz
cd LuaJIT-2.1.0-beta2
make PREFIX=/home/soft/luajit
make install PREFIX=/home/soft/luajit

2. 下载ngx_devel_kit(NDK)模块 :https://github.com/simpl/ngx_devel_kit/tags,不需要安装

wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz
tar -zxvf v0.2.19.tar.gz

3.下载lua-nginx-module 模块 :https://github.com/openresty/lua-nginx-module/tags,不需要安装 , 我开始使用了最新版本v0.10.15,有报错,遇到这种情况修改下版本

wget https://github.com/openresty/lua-nginx-module/archive/v0.10.13.tar.gz
tar -zxvf v0.10.2.tar.gz

4. nginx -V查看已经编译的配置 ,如下

--prefix=/home/soft/nginx --with-http_stub_status_module --with-http_ssl_module

现在要做的是添加上面的模块

./configure --prefix=/home/soft/nginx --with-http_stub_status_module --with-http_ssl_module --with-ld-opt=-Wl,-rpath,/home/soft/luajit/lib --with-luajit --add-module=/home/soft/ngx_devel_kit-0.2.19 --add-module=/home/soft/lua-nginx-module-0.10.13

5.添加环境变量

vim /etc/profile

export LUAJIT_LIB=/home/soft/luajit/lib
export LUAJIT_INC=/home/soft/luajit/include/luajit-2.1

//实时生效
source /etc/profile

6.重新编译安装nginx,进入nginx的解压目录

./configure --prefix=/home/soft/nginx --with-http_stub_status_module --with-http_ssl_module --with-ld-opt=-Wl,-rpath,/home/soft/luajit/lib --with-luajit --add-module=/home/soft/ngx_devel_kit-0.2.19 --add-module=/home/soft/lua-nginx-module-0.10.13

make && make install

7.查看是否编译成功

在nginx配置文件加入下列配置

vim nginx/conf/nginx.conf

location /testlua { 
      default_type 'text/plain'; 
      content_by_lua 'ngx.say("hello, lua")'; 
}

8.重新启动nginx,访问

localhost/testlua

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值