Nginx中安装Lua模块

1.基本安装步骤

在安装Lua模块时,建议先查看一下下面列举的问题。另外先安装openssl-devel软件。

(1)首先通过nginx -V命令检查

(2)进入opt/download目录下(个人习惯将下载的内容放在这个目录)

# 下载LuaJIT安装包
[root@xfcy download]# wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz
# 解压LuaJIT
[root@xfcy download]# tar -zvxf LuaJIT-2.0.5.tar.gz
# 进入解压后的LuaJIT-2.0.5目录,执行下面命令(建议设置名称LuaJIT为小写,否则容易出错)
[root@xfcy LuaJIT-2.0.5]# make install  PREFIX=/usr/local/luajit

(3)配置环境变量

# 使用 vim /etc/profile 打开配置文件,配置下面内容
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
# 然后保存配置
source  /etc/profile 

(4)下载ngx_devel_kitlua-nginx-module

# 下载ngx_devel_kit 到/opt/download目录
[root@xfcy download]# wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
# 解压
[root@xfcy download]# tar -zxvf v0.3.0.tar.gz

# 下载lua-nginx-module 到/opt/download目录
[root@xfcy download]# wget https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc7.tar.gz
# 解压
[root@xfcy download]# tar -zxvf v0.10.9rc7.tar.gz

(5)下载nginx,(如果之前安装过nginx,建议版本一致),重新编译

# 下载nginx-1.16.1版本
[root@xfcy download]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
# 解压
[root@xfcy download]# tar -zxvf nginx-1.16.1.tar.gz
# 进入nginx重新编译,为了不出错,建议先用nginx -V,得到下面配置的前半部分
[root@xfcy nginx-1.16.1]# ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=/opt/download/ngx_devel_kit-0.3.0 --add-module=/opt/download/lua-nginx-module-0.10.9rc7
# 注意上面最后的两个需要填写ngx_devel_kit-0.3.0和lua-nginx-module-0.10.9rc7绝对路径

# 重新编译
[root@xfcy nginx-1.16.1]# make
[root@xfcy nginx-1.16.1]# make install

# 加载lua库,加入到ld.so.conf文件
[root@xfcy nginx-1.16.1]# echo "/usr/local/luajit/lib" >> /etc/ld.so.conf
[root@xfcy nginx-1.16.1]# ldconfig

(6)检查是否成功

# 检查
[root@xfcy nginx-1.16.1]# nginx -t
# 重启
[root@xfcy nginx-1.16.1]# systemctl restart nginx

(7)如果成功,将会显示下面结果。

2. 常见问题

(1)报OpenSSL错误

……
checking for OpenSSL library ... not found
checking for OpenSSL library in /usr/local/ ... not found
checking for OpenSSL library in /usr/pkg/ ... not found
checking for OpenSSL library in /opt/local/ ... not found
……

解决方法

# 安装openssl-devel
yum install openssl-devel

(2)报libluajit-5.1.so.2错误。

[root@xfcy nginx-1.16.1]# nginx -t
nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such fileectory

解决方法

# 加载lua库,加入到ld.so.conf文件
[root@xfcy nginx-1.16.1]# echo "/usr/local/luajit/lib" >> /etc/ld.so.conf
[root@xfcy nginx-1.16.1]# ldconfig

以上便是在nginx中安装Lua模块中出现的问题。

3. 参考文献

  1. 慕课手记-Nginx编译安装Lua模块

  2. 简书-Nginx添加Lua扩展

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值