将LUA模块添加到nginx

Sci*_*nus 2 lua nginx

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

我在/ opt/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;
    }
}
Run Code Online (Sandbox Code Playgroud)

lua_access_file导致错误

nginx:[emerg] unknown指令"access_by_lua_file"我是否需要在配置中定义一些"include"来摆脱这个?

谢谢.

Aks*_*ate 6

根据问题和我的理解,我正在将你的问题分解为小任务.

1)错误清楚地表明您没有正确安装Lua-nginx模块.

Lua-nginx模块文档

2)服务器无法访问互联网,因此无法从git下载. *

3)使用lua-nginx-module安装nginx的步骤.

  • lua nginx模块兼容性检查.

    Nginx Compatibility
        The latest version of this module is compatible with the following versions of Nginx:
    
        1.13.x (last tested: 1.13.6)
        1.12.x
        1.11.x (last tested: 1.11.2)
        1.10.x
        1.9.x (last tested: 1.9.15)
        1.8.x
        1.7.x (last tested: 1.7.10)
        1.6.x
    
        Nginx cores older than 1.6.0 (exclusive) are not supported.
    
    Run Code Online (Sandbox Code Playgroud)

    nginx兼容性的referance文档

  • 先决条件

    - Centos/RHEL [ 如果您的服务器正在使用互联网 ].

    yum install -y wget unzip gcc make openssl-devel pcre-devel zlib-devel 
    
    Run Code Online (Sandbox Code Playgroud)

    - 手动下载.rpm包并安装.

    1. 从RPM资源站点搜索先决条件

    2. 将文件复制到Linux框中

      • 请参考上述第(2)项" 服务器无法访问互联网,因此无法从git下载 ".
    3. 使用以下命令安装.

        rpm -i rpm-package-name
      
      Run Code Online (Sandbox Code Playgroud)

      安装-RPM-文件上的Linux

    - 为先决条件安装Tarball.

  • 下载源代码

    $ cd /tmp/nginx-build
    
    $ wget http://nginx.org/download/nginx-1.13.0.tar.gz
    
    $ wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
    
    $ wget -O nginx_devel_kit.tar.gz https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
    
    $ wget -O nginx_lua_module.tar.gz https://github.com/openresty/lua-nginx-module/archive/v0.10.8.tar.gz
    
    Run Code Online (Sandbox Code Playgroud)
  • 提取

     $ tar xvf LuaJIT-2.0.4.tar.gz
    
     $ tar xvf nginx-1.11.10.tar.gz
    
     $ tar xvf nginx_devel_kit.tar.gz
    
     $ tar xvf nginx_lua_module.tar.gz
    
    Run Code Online (Sandbox Code Playgroud)
  • 建立LuaJIT

    要使用LuaJIT构建Nginx,我们需要首先构建LuaJIT.这就像make命令一样简单

       $ cd /tmp/nginx-build/LuaJIT-2.0.4
       $ make install
        ==== Building LuaJIT 2.0.4 ====
        make -C src
        make[1]: Entering directory `/tmp/nginx/LuaJIT-2.0.4/src'
        ...
        ...
        ln -sf luajit-2.0.4 /usr/local/bin/luajit
        ==== Successfully installed LuaJIT 2.0.4 to /usr/local ====
    
    Run Code Online (Sandbox Code Playgroud)
  • 建立Nginx

        $ cd /tmp/nginx-build/nginx-1.11.10
        $ LUAJIT_LIB=/usr/local/lib LUAJIT_INC=/usr/local/include/luajit-2.0 \
        ./configure \
        --user=nobody                          \
        --group=nobody                         \
        --prefix=/etc/nginx                   \
        --sbin-path=/usr/sbin/nginx           \
        --conf-path=/etc/nginx/nginx.conf     \
        --pid-path=/var/run/nginx.pid         \
        --lock-path=/var/run/nginx.lock       \
        --error-log-path=/var/log/nginx/error.log \
        --http-log-path=/var/log/nginx/access.log \
        --with-http_gzip_static_module        \
        --with-http_stub_status_module        \
        --with-http_ssl_module                \
        --with-pcre                           \
        --with-file-aio                       \
        --with-http_realip_module             \
        --without-http_scgi_module            \
        --without-http_uwsgi_module           \
        --without-http_fastcgi_module ${NGINX_DEBUG:+--debug} \
        --with-cc-opt=-O2 --with-ld-opt='-Wl,-rpath,/usr/local/lib' \
        --add-module=/tmp/nginx/ngx_devel_kit-0.3.0 \
        --add-module=/tmp/nginx/lua-nginx-module-0.10.8
        $ make install
    
    Run Code Online (Sandbox Code Playgroud)
  • Syntanx检查

     $ nginx -t
        nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
        nginx: configuration file /etc/nginx/nginx.conf test is successful
    
    Run Code Online (Sandbox Code Playgroud)
  • Nginx Lua测试

    *根据你的nginx文件.

     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'; }
    
    Run Code Online (Sandbox Code Playgroud)
  • 重新加载/重新启动nginx

        systemctl nginx restart
        systemctl nginx reload.
    
    Run Code Online (Sandbox Code Playgroud)

    如何对重载-nginx的-systemctl或 - nginx的-S

  • @ScipioAfricanus是的,我完全理解构建“ Lua-nginx-module”有些棘手,并且有时无法提供预期的结果。我也面临许多问题,经过几次尝试起草了这份文件。它对我有用,请尝试一下。请告诉我们,它对您有何帮助。 (2认同)
  • @Akshaybarahate,我遇到 make install /home/nginx-build/lua-nginx-module-0.10.8/src/ngx_http_lua_headers.c:227:15 错误:错误:分配给类型 'ngx_buf_t * {aka struct 时类型不兼容ngx_buf_s *}' 来自类型 'ngx_chain_t {aka struct ngx_chain_s}' b = hc->busy[i]; ^ objs/Makefile:1446: 目标 'objs/addon/src/ngx_http_lua_headers.o' 的配方失败 make[1]: *** [objs/addon/src/ngx_http_lua_headers.o] 错误 1 ​​make[1]: 离开目录'/home/nginx-build/nginx-1.19.3' Makefile:11: 目标'安装'的配方失败 make: *** [安装] 错误 2 (2认同)

Pie*_*erz 6

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

sudo apt install libnginx-mod-http-lua
Run Code Online (Sandbox Code Playgroud)

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