gpt4 book ai didi

nginx - 将 LUA 模块添加到 nginx

转载 作者:行者123 更新时间:2023-12-03 15:21:58 25 4
gpt4 key购买 nike

我在 redhat 7.5 服务器上 rpm 安装了 nginx 1.12,它也有 LUA 5.1.4
我下载了 lua-nginx-module-0.10.13 tar 球并将其放在/etc/nginx/modules 下,但我无法使用 LUA 身份验证文件运行 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] 未知指令“access_by_lua_file”我需要在配置中定义一些“包含”来摆脱这个吗?

谢谢。

最佳答案

根据问题和我的理解,我将您的问题分解为小任务。
1)错误清楚地表明您没有正确安装Lua-nginx-module。
Lua-nginx-module documentation
2)服务器无法访问互联网,因此无法从 git 下载。
*

  • 假设您正在从 Windows 对您的机器执行 ssh。所以,请
    检查以下链接以将文件从 Windows 复制到 Linux。
    Installing/Accessing via WinSCP

  • how-to-copy-files-from-one-machine-to-another-using-ssh
  • 此步骤将在您的服务器上获取所有必要的文件。

  • 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.
    referance document for nginx compatibility
  • 先决条件
    **- Centos/RHEL**[**In case if internet is working in your server**].

    yum install -y wget unzip gcc make openssl-devel pcre-devel zlib-devel
    - 手动下载 .rpm 包并安装。
  • 从 RPM 资源站点搜索先决条件
  • RPM resource site

  • 将文件复制到您的 Linux 框中
  • 请引用上面第(2)点“服务器无法访问互联网,因此无法从git下载”。
  • 使用以下命令安装。
      rpm -i rpm-package-name

  • Install-rpm-file-on-linux

    - 先决条件的压缩包安装。
     - [Installing gcc from source code ][6]         Similarly,you can look for
    other prerequistes.
  • 下载源码
     $ rm -fr /tmp/nginx-build  
    $ mkdir /tmp/nginx-build
    $ 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
  • 提取
      $ 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
  • 构建 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 ====
  • 搭建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
  • 语法检查
      $ nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
  • 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'; }
  • 重新加载/重启 nginx
         systemctl nginx restart
    systemctl nginx reload.

  • how-to-reload-nginx-systemctl-or-nginx-s

    关于nginx - 将 LUA 模块添加到 nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50357732/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com