nginx - 如何在 nginx 上安装模块?

标签 nginx module nginx-config

运行 nginx -t 时出现此错误:

nginx: [emerg] unknown directive "subs_filter_types" in /etc/nginx/sites-enabled/my.site.com.conf:285
nginx: configuration file /etc/nginx/nginx.conf test failed

所以我需要安装替换过滤器模块并在 nginx 文档中 https://www.nginx.com/resources/wiki/modules/substitutions/#subs-filter-types
其中说运行这些命令:
git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
./configure --add-module=/path/to/module

问题是我的 nginx 安装中的任何地方都没有配置脚本,也没有
git 存储库。我真的不明白。
至少我想知道那个 nginx 配置脚本的内容。

最佳答案

您所指的说明适用于编译安装。
假设你想将模块添加到现有的 NGINX 安装中,下面是让事情运行的通用步骤。

  • 从 nginx.org 获取与您安装的版本完全匹配的 NGINX 到您的系统,然后将其提取到,例如 /usr/local/src/nginx
  • git clone NGINX 模块的源代码到您的系统上,例如/usr/local/src/nginx-module-foo
  • cd /usr/local/src/nginx .在这里您可以找到 configure脚本。您将基本上使用 config 的位置配置 NGINX。有问题的特定模块,因此下一步:
  • ./configure --add-dynamic-module=../nginx-module-foo --with-compat
  • make

  • 作为编译的结果,您将拥有模块的 .so文件位于 objs 中的某处你的 NGINX 源目录。然后,您将其复制到例如/usr/lib64/nginx/modules/目录。
    要让您现有的 NGINX 加载模块,请添加 load_module modules/foo.so;/etc/nginx/nginx.conf 的最顶端.
    您可以解读整个编译方法的许多缺点:一个是在生产系统上安装编译软件(gcc),另一个是在升级 NGINX 或模块时必须重新执行所有这些步骤。
    由于上述原因,您可能希望搜索第三方模块的打包安装。
    对于 CentOS/RHEL 系统,您可能想查看 GetPageSpeed repos(订阅软件,我倾向于提及它,因为我是维护者。但在撰写本文时,这对 CentOS/RHEL 8 是免费的. 安装你想要的模块,goes down 到几个命令:
    yum -y install https://extras.getpagespeed.com/release-latest.rpm
    yum -y install nginx-module-substitutions
    
    对于基于 Debian 的系统,可能存在相同的替代 PPA。

    关于nginx - 如何在 nginx 上安装模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59988807/

    相关文章:

    module - Electron 原子 - 编译后找不到模块 "Node-Windows"

    kubernetes - nginx 到上游 headless (headless)服务的连接被拒绝,但我可以从 webapp 容器中 curl

    php - 将 wordpress 站点从 Nginx 移动到专用服务器 Windows

    php - Magento 2 事件观察器不工作

    nginx - 将 nginx conf 挂载为 docker 卷会导致系统错误 boot2docker

    python - 导入 Python 模块会影响性能吗?

    javascript - Vuejs 应用程序显示无效的主机 header 错误循环

    nginx - 基于referer的nginx条件路由

    node.js - 使用哈希方法与 nginx 进行负载平衡

    nginx 代理 ELK