向Nginx添加LUA模块

我在redhat 7.5服务器上安装了Nginx 1.12并且它也有LUA 5.1.4 我下载了lua-nginx-module-0.10.13 tar ball并将其放在/etc/nginx/modules下,但我无法通过LUA auth文件运行Nginx。

我还在/opt/openresty/下安装了openresty。

http://openresty.org/en/installation.html 我在这里按照“make”方法进行了操作。

不幸的是,此服务器无法访问互联网,因此我无法从git中安装软件,这大大降低了速度。我不知道如何在此处添加模块。任何评论都将有所帮助。

这是我的nginx配置文件的样子..

server
{
    listen 80;

    access_log  /opt/elk/logs/nginx/access.log  main;

    #auth_basic "admin";
    #auth_basic_user_file "/etc/nginx/passwd";

    client_max_body_size 100M;

    location /
    {
        proxy_pass http://127.0.0.1:9200;

        keepalive_timeout 300s;

        #auth_basic on;
        auth_basic "admin";
        auth_basic_user_file "/etc/nginx/passwd";

        access_by_lua_file '/etc/nginx/authorized.lua';
    }

    error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html
    {
        root   /usr/share/nginx/html;
    }
}

lua_access_file导致错误

nginx: [emerg] unknown directive "access_by_lua_file" 这是否需要定义一些“include”在配置文件中才能消除这个问题?

谢谢。

点赞
用户7265288
用户7265288

Akshay barahate 的回答详尽全面。然而,为了回答你的问题:

是否有一些 "include" 我需要在配置中定义来解决这个问题?

尝试添加

load_module "ngx_http_lua_module.so"

包名可能会有所不同,上述文件名派生自 Ubuntu 18.04 安装包。 (通常你会在 /usr/share/nginx/modules 中找到你的模块)

注意:如果你从源代码编译 nginx(似乎是让 Lua 运行的推荐方式),路径和文件名可能会有所不同。

祝你编码愉快。

2020-03-31 15:33:16
用户10577550
用户10577550

如果您正在使用docker运行nginx,则可以按照docker-nginx Github存储库上的说明进行操作。

nginx-conf中,确保通过添加以下方式加载模块:

load_module modules/ndk_http_module.so;
load_module modules/ngx_http_lua_module.so;
load_module modules/ngx_stream_lua_module.so;
2021-03-03 12:13:39
用户436794
用户436794

现在,在大多数操作系统(例如Ubuntu等)中,可以通过安装 libnginx-mod-http-lua 包来启用对 Nginx 的 Lua 支持。例如:

sudo apt install libnginx-mod-http-lua

该软件包包括动态库和相应的 load_module 指令 /usr/share/nginx/modules-available/mod-http-lua.conf,通常在安装软件包时启用(通过将其软链接到 /etc/nginx/modules-enabled/ 目录中)。

2023-01-06 10:11:11