如何在nginx上安装模块?

Czi*_*pO2 4 module nginx 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
Run Code Online (Sandbox Code Playgroud)

所以我需要安装替换过滤器模块,并在 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
Run Code Online (Sandbox Code Playgroud)

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

Dan*_*nin 10

您所指的说明用于编译安装。

假设您想将该模块添加到现有的NGINX 安装中,以下是使事情运行的通用步骤。

  1. 从 nginx.org 获取与您安装的版本完全匹配的 NGINX 版本并将其解压缩到,例如, /usr/local/src/nginx
  2. git clone NGINX 模块的源代码到您的系统上,例如 /usr/local/src/nginx-module-foo
  3. cd /usr/local/src/nginx. 您将在此处找到configure脚本。您将基本上使用相关config特定模块的位置配置 NGINX ,因此下一步:
  4. ./configure --add-dynamic-module=../nginx-module-foo --with-compat
  5. make

作为编译的resulf,您将.soobjsNGINX 源目录中的某处拥有模块文件。然后您将其复制到例如/usr/lib64/nginx/modules/目录。

要使现有的 NGINX 加载模块,请load_module modules/foo.so;/etc/nginx/nginx.conf.

您可以解读整个编译方法的许多缺点:一个是gcc在生产系统上安装了编译软件 ( ),另一个是在升级 NGINX 或模块时必须重新执行所有这些步骤。

出于上述原因,您可能想要搜索第三方模块的打包安装。

对于 CentOS/RHEL 系统,您可能想查看 GetPageSpeed 存储库(订阅软件,我倾向于提及它,因为我是维护者。但在撰写本文时,这对 CentOS/RHEL 8 是免费的. 安装你想要的模块,归结为几个命令:

yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install nginx-module-substitutions
Run Code Online (Sandbox Code Playgroud)

对于基于 Debian 的系统,可能存在替代的 PPA。