问题
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.
回答1:
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.
- 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
git clone
NGINX module's source code onto your system, to e.g./usr/local/src/nginx-module-foo
cd /usr/local/src/nginx
. This is where you will find theconfigure
script. You will basically configure NGINX with the location of theconfig
of specific module in question, thus next step:./configure --add-dynamic-module=../nginx-module-foo --with-compat
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.
回答2:
Just replace prefix subs with sub.
For default nginx 1.10.3 installation (Ubuntu 16.04.5 LTS)
nginx -V should have flag --with-http_sub_module to use sub_* directives.
Usage example:
sub_filter_types text/html text/css text/xml;
sub_filter 'needle' 'replacement';
sub_filter_once off;
NGINX documentation link
来源:https://stackoverflow.com/questions/59988807/how-to-install-a-module-on-nginx