当前位置: 首页 > 编程笔记 >

Nginx安装lua-nginx-module模块的方法步骤

濮阳浩穰
2023-03-14
本文向大家介绍Nginx安装lua-nginx-module模块的方法步骤,包括了Nginx安装lua-nginx-module模块的方法步骤的使用技巧和注意事项,需要的朋友参考一下

ngx_lua_module 是一个nginx http模块,它把 lua 解析器内嵌到 nginx,用来解析并执行lua 语言编写的网页后台脚本

特性很牛叉,可自行百度查看,这里主要是示范一下,如何在Nginx下安装lua-nginx-module模块

当然,如果你之前没有安装过Nginx,而且嫌安装麻烦,可直接下载openresty安装简单快捷,http://openresty.org/cn/installation.html(阿里的大牛章亦春的作品,膜拜~~~)

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.2.19.tar.gz
tar -xzvf v0.2.19.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.2.tar.gz
tar -xzvf v0.10.2.tar.gz

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

nginx -V

笔者的配置如下:

--prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-openssl=../openssl-1.0.2h --with-pcre=../pcre-8.38 --with-pcre-jit --with-ld-opt=-ljemalloc --with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib --add-module=/usr/local/src/ngx_devel_kit-0.2.19 --add-module=/usr/local/src/lua-nginx-module-0.10.2

5.进入之前安装nginx的解压目录,重新编译安装(在nginx -V得到的配置下,加入ngx_devel_kit-0.2.19和ua-nginx-module-0.10.2的目录),最终的配置如下:

设置环境变量

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

./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-openssl=../openssl-1.0.2h --with-pcre=../pcre-8.38 --with-pcre-jit --with-ld-opt='-ljemalloc' --with-ld-opt="-Wl,-rpath,/usr/local/luajit/lib" --add-module=/usr/local/src/ngx_devel_kit-0.2.19 --add-module=/usr/local/src/lua-nginx-module-0.10.2

6.编译安装

make -j2
make install

7.查看是否编译成功

在/usr/local/nginx/conf/nginx.conf中加入如下代码:

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

重启nginx:

service nginx restart

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

hello, lua

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持小牛知识库。

 类似资料:
  • This module embeds the Lua interpreter or LuaJIT into the nginx core and integrates the powerful Lua threads (aka Lua coroutines) into the nginx event model by means of nginx subrequests. Unlike Apach

  • lua-nginx-module (ngx_lua) 可在 Nginx 中嵌入 Lua 语言。让 Nginx 可以支持 Lua 强大的语法。 概要: # set search paths for pure Lua external libraries (';;' is the default path): lua_package_path '/foo/bar/?.lua;/blah/?.lua;

  • This Nginx C module exposes a Lua API to Lua Nginx Module for classic Nginx upstreams. Documentation: https://github.com/agentzh/lua-upstream-nginx-module Project page: https://github.com/agentzh/lua-

  • ngx_tcp_lua_module-将Lua的功能嵌入Nginx服务器。在tcp流模式下工作。 基于nginx1.4.1版本, 本着精简,高效,模块化等原则,吸收nginx-http-lua模块(https://github.com/openresty/lua-nginx-module), tcp_lua模块(https://github.com/bigplum/nginx-tcp-lua-mo

  • 这个软件是 Nginx C 模块用于展示 Lua API 给 ngx_lua for Nginx upstreams 。该模块可以用于生产环境。   Synopsis http {    upstream foo.com {        server 127.0.0.1 fail_timeout=53 weight=4 max_fails=100;        server agentzh.o

  • 本文向大家介绍Nginx之为已安装nginx动态添加模块的方法,包括了Nginx之为已安装nginx动态添加模块的方法的使用技巧和注意事项,需要的朋友参考一下 说明: 已经安装好的nginx,需要添加一个未被编译安装的模块,需要怎么弄呢? 具体: 这里以安装第三方ngx_http_google_filter_module模块为例 nginx的模块是需要重新编译nginx,而不是像apache一样配