• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

nginx 添加lua 支持 :安装

武飞扬头像
向右看齐--
帮助8

基于lnmp 在nginx中安装lua,并启用redis进行访问拦截;

宝塔下安装查看:https://www.cnblogs.com/l-zl/p/16598926.html

安装过程如下:

1. 安装lua,下载LuaJIT

  1.  
    cd /data/install/
  2.  
    wget -c https://github.com/openresty/luajit2/archive/refs/heads/v2.1-agentzh.zip

解压并重命名为lua,进入到目录中

在安装前需要打开makefile文件并找到

LDCONFIG= ldconfig -n 将其修改成: LDCONFIG= /sbin/ldconfig -n
  1.  
    make
  2.  
    make install PREFIX=/usr/local/luajit

添加环境变量: 

  1.  
    export LUAJIT_LIB=/usr/local/luajit/lib
  2.  
    export LUAJIT_INC=/usr/local/luajit/include/luajit-2.1

加载类库:

  1.  
    cat > /etc/ld.so.conf.d/luajit.conf<<EOF
  2.  
    /usr/local/luajit/lib
  3.  
    EOF
  4.  
    ldconfig

2. 安装ngx_devel_kit和lua-nginx-module 

下载 lua-nginx-module 地址:https://github.com/openresty/lua-nginx-module 并解压

  1.  
    wget -c https://github.com/openresty/lua-nginx-module/archive/refs/tags/v0.10.14.tar.gz
  2.  
    tar zxf v0.10.14.tar.gz

 下载 ngx_devel_kit 地址:https://github.com/simpl/ngx_devel_kit 并解压

  1.  
    wget -c https://github.com/vision5/ngx_devel_kit/archive/refs/tags/v0.3.1.tar.gz
  2.  
    tar zxf v0.3.1.tar.gz

lnmp一键包目录下的lnmp.conf文件里的Nginx_Modules_Options加上编译参数

--with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib --add-module=/data/install/lua/lua-nginx-module --add-module=/data/install/lua/ngx_devel_kit

Nginx_Modules_Options='--with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib --add-module=/data/install/lua/lua-nginx-module --add-module=/data/install/lua/ngx_devel_kit'

lnmp一键包中升级脚本

执行upgrade.sh 这里是重点,如果仅仅是新增模块的话,则只需要填写与当前版本号相同的版本号即可,如果填写大于当前的版本号则代表的是升级新版本并安装指定扩展

  1.  
    cd /data/install/lnmp1.8
  2.  
    ./upgrade.sh nginx

回车之后会让你输入要升级的版本号,此处可填写当前版本号

执行完之后检查是否安装成功,出现报错1:说resty.core模块找不到

nginx: [alert] detected a LuaJIT version which is not OpenResty's; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty's LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html)

解决:

先卸载原有luajit

  1.  
    cd /data/install/lua
  2.  
    make uninstall

然后从https://github.com/openresty/luajit2下载安装

  1.  
    git clone https://github.com/openresty/luajit2
  2.  
    mv luajit2 lua && cd lua
  3.  
    make && make install

参考的地址:https://www.cnblogs.com/trustnature/articles/15250071.html

nginx -s reload  重启

nginx -V 查看安装情况

3. 下载lua链接redis的一个模块

下载 https://github.com/openresty/lua-resty-redis

  1.  
    wget -c https://github.com/openresty/lua-resty-redis/archive/refs/tags/v0.30.tar.gz
  2.  
    tar zxf v0.30.tar.gz

解压之后直接make install即可

  1.  
    cd lua-resty-redis-0.30
  2.  
    make install

返回结果:

学新通

4. nginx配置

nginx.conf 中增加引入lua路径 lua_package_path "/usr/local/lib/lua/resty/?.lua;/data/lua/?.lua;;";

vhost中的没个配置文件中的 php部分增加引入access_by_lua_file /data/lua/nginx_client_ip.lua;

5. 小问题

使用阿里云redis时,通过域名连接老是提示连接失败,报错:failed to connect: no resolver defined to resolve

解决方案:增加DNS配置,在conf配置文件中增加resolver配置,

学新通

问题解决浏览的地址:谢谢三位大哥

https://learnku.com/articles/27778

https://blog.csdn.net/百度_19473529/article/details/117738193

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhefccjj
系列文章
更多 icon
同类精品
更多 icon
继续加载