如何在nginx上安装模块? [英] How to install a module on nginx?

查看:54
本文介绍了如何在nginx上安装模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

nginx: [emerg]/etc/nginx/sites-enabled/my.site.com.conf:285 中的未知指令subs_filter_types"nginx: 配置文件/etc/nginx/nginx.conf 测试失败

所以我需要安装替换过滤器模块并在 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 安装中,以下是使事情运行的通用步骤.

  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. 制作

作为编译的补充,您将在 NGINX 源代码的 objs 目录中的某处拥有模块的 .so 文件.然后您将其复制到例如/usr/lib64/nginx/modules/ 目录.

要让现有的 NGINX 加载模块,请在 /etc/nginx/nginx.conf 的最顶部添加 load_module modules/foo.so;.>

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

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

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

yum -y install https://extras.getpagespeed.com/release-latest.rpmyum -y 安装 nginx-module-substitutions

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

When running nginx -t I get this error:

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

So I need to install the substitution filter module and in the nginx documentation https://www.nginx.com/resources/wiki/modules/substitutions/#subs-filter-types Which says to run these commands:

git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
./configure --add-module=/path/to/module

The problem is I don't have the configure script anywhere in my nginx installation nor in the git repository. I really don't understand. At the very least I want to know the content of that nginx configure script.

解决方案

The instructions you are referring to are for compiled installation.

Assuming you want to add the module to your existing NGINX install, below are the generic steps that will get things running.

  1. Fetch exactly matching version of NGINX as the one you have installed, from nginx.org onto your system and extract it to, say, /usr/local/src/nginx
  2. git clone NGINX module's source code onto your system, to e.g. /usr/local/src/nginx-module-foo
  3. cd /usr/local/src/nginx. This is where you will find the configure script. You will basically configure NGINX with the location of the config of specific module in question, thus next step:
  4. ./configure --add-dynamic-module=../nginx-module-foo --with-compat
  5. make

As a resulf of the compilation you will have module's .so file somewhere in objs directory of your NGINX sources. You will then copy it over to e.g. /usr/lib64/nginx/modules/ directory.

To make your existing NGINX load the module, add load_module modules/foo.so; at the very top of /etc/nginx/nginx.conf.

You can decipher the many downsides to the whole compiled approach: one is having compilation software (gcc) on a production system, other is having to re-do all those steps any time you upgrade NGINX or the module.

For the reasons mentioned, you might want to search for a packaged install of third-party modules.

For CentOS/RHEL systems, you might want to look at GetPageSpeed repos (subscription-ware, and I'm biased to mention it, because I'm the maintainer. But this is free for CentOS/RHEL 8 at the time of this writing. Installing the module you want, goes down to a couple of commands:

yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install nginx-module-substitutions

For Debian-based systems, probably there are alternative PPAs existing for the same.

这篇关于如何在nginx上安装模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆