nginx 增加nginx_lua_module模块的方法实现

 更新时间:2026年05月27日 08:29:53   作者:DDDDemo  
本文详细介绍了在NGINX V1.14.0上安装lua-nginx-module模块的过程,包括LuaJIT2.1、ngx_devel_kit V0.3.0和lua_nginx_module V0.10.13的安装步骤,感兴趣的可以了解一下

版本说明:

NGINX:V1.14.0

LuaJIT:V2.1.0

ngx_devel_kit:V0.3.0

lua_nginx_module:V0.10.13

安装步骤:

1. 下载安装LuaJIT 2.1(2.0或者2.1都是支持的,官方推荐2.1):http://luajit.org/download.html

cd /usr/local/src
wget http://luajit.org/download/LuaJIT-2.1.0-beta2.tar.gz
tar zxf LuaJIT-2.1.0-beta2.tar.gz
cd LuaJIT-2.1.0-beta2
make PREFIX=/usr/local/luajit
make install PREFIX=/usr/local/luajit

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

cd /usr/local/src
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
tar -zxvf v0.3.0.tar.gz

3. 下载最新的lua-nginx-module 模块 :https://github.com/openresty/lua-nginx-module/tags,不需要安装

cd /usr/local/src
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.13.tar.gz
tar -xzvf v0.10.13.tar.gz

4. 因为我之前安装有NGINX,是用yum install命令安装的,此时我做的一件事情是,用源码安装替换掉原来的。

  • 4.1 nginx -V (nginx -V查看已经编译的配置),我的配置内容如下:
--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=/usr/local/src/ngx_devel_kit-0.2.19 
--add-module=/usr/local/src/lua-nginx-module-0.10.2
  • 4.2 备份文件
mv /usr/sbin/nginx /usr/sbin/nginx.20190218
cp -r /etc/nginx /etc/nginx.20190218
  • 4.3 下载NGINX源码包
http://nginx.org/download/nginx-1.14.0.tar.gz 
tar zxvf nginx-1.14.0.tar.gz 
  • 4.4 设置环境变量
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.1
  • 4.5 编译安装NGINX。首先将4.1提到的nginx -V获取到的已经编译的配置,添加如下内容
 --add-module=/usr/local/src/ngx_devel_kit-0.3.0 --add-module=/usr/local/src/lua-nginx-module-0.10.13

添加后依次执行如下命令:

./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=/usr/local/src/ngx_devel_kit-0.3.0 --add-module=/usr/local/src/lua-nginx-module-0.10.13
make -j2
make install

5. 查看是否编译成功

在/etc/nginx/conf.d/default.conf (根据每个人安装配置决定)中加入如下代码:

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

重启nginx:

service nginx restart

访问http://ip/hello_lua会出现”hello, lua”表示安装成功

到此这篇关于nginx 增加nginx_lua_module模块的文章就介绍到这了,更多相关nginx nginx_lua_module模块内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • PHP(FastCGI)在Nginx的alias下出现404错误的解决方法

    PHP(FastCGI)在Nginx的alias下出现404错误的解决方法

    这篇文章主要介绍了PHP(FastCGI)在Nginx的alias下出现404错误的解决方法,涉及nginx平台的相关配置技巧,需要的朋友可以参考下
    2016-05-05
  • 详解Nginx配置多站点需要踩的坑

    详解Nginx配置多站点需要踩的坑

    本篇文章主要介绍了详解Nginx配置多站点需要踩的坑,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-02-02
  • Nginx 禁止IP访问 只允许域名访问

    Nginx 禁止IP访问 只允许域名访问

    今天要在Nginx上设置禁止通过IP访问服务器,只能通过域名访问,这样做是为了避免别人把未备案的域名解析到自己的服务器IP而导致服务器被断网,从网络上搜到以下解决方案
    2016-09-09
  • Nginx更换ssl证书不生效的问题解决

    Nginx更换ssl证书不生效的问题解决

    本文主要介绍了Nginx配置中更换SSL证书后,新证书不生效的问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2024-12-12
  • Nginx 配置 proxy_hide_header 隐藏后端 Server 的版本信息的实现

    Nginx 配置 proxy_hide_header 隐藏后端 Server&n

    Nginx反向代理场景中,后端服务常会在响应头中暴露版本信息,使用proxy_hide_header指令可以在Nginx层将其过滤掉,本文就来详细的介绍一下Nginx隐藏后端 Server 的版本信息的实现,感兴趣的可以了解一下
    2026-04-04
  • 反向代理缓存的详细介绍

    反向代理缓存的详细介绍

    这篇文章主要介绍了反向代理缓存的详细介绍的相关资料,希望通过本文大家能够掌握应用反向代理缓存的使用方法,需要的朋友可以参考下
    2017-09-09
  • Nginx location静态文件映射配置过程

    Nginx location静态文件映射配置过程

    文章介绍了Nginx配置中root和alias指令的使用场景和区别,并通过实际问题分析,指出路径拼接逻辑错误导致静态文件无法访问,最终解决方案是将root改为alias,并确保路径正确
    2025-12-12
  • 详解nginx upstream 配置和作用

    详解nginx upstream 配置和作用

    这篇文章主要介绍了详解nginx upstream 配置和作用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-07-07
  • Nginx出现504 Gateway Time-out的解决方法

    Nginx出现504 Gateway Time-out的解决方法

    nginx访问出现504 Gateway Time-out,一般是由于程序执行时间过长导致响应超时,本文就来介绍一下解决方法,感兴趣的可以了解一下
    2023-10-10
  • nginx正向代理https网站的实现

    nginx正向代理https网站的实现

    Nginx正向代理,通过服务器代理客户端去重定向请求访问到目标服务器的一种代理服务,本文主要介绍了nginx正向代理https网站的实现,具有一定的参考价值,感兴趣的可以了解一下
    2024-05-05

最新评论