5

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.

CzipO2
  • 403
  • 1
  • 6
  • 15
  • Do you mean [`sub_filter_types`](http://nginx.org/en/docs/http/ngx_http_sub_module.html#sub_filter_types)? – Richard Smith Jan 30 '20 at 17:05
  • I don't know. Subs (substitution) is what I got. It probably is the same thing. – CzipO2 Jan 31 '20 at 10:14
  • Or probably not. I get the same error message using `subs_filter_types` instead of `sub_filter_types`, and my Nginx comes with that module already built in. – Richard Smith Jan 31 '20 at 10:43

2 Answers2

11

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.

Danila Vershinin
  • 8,725
  • 2
  • 29
  • 35
  • What do you mean by fetching my version of nginx? This is my version "nginx version: nginx/1.14.0 (Ubuntu)" and I have nothing in my /usr/local/src. IN /etcnginx there is a folder called modules-enabled, what is that for then? Thanks for replying. – CzipO2 Jan 31 '20 at 08:41
  • Fetching your version of nginx means going to nginx.org website, and downloading .tar.gz file which is the same version as the one you have currently installed. E.g. in your case it is [this archive](http://nginx.org/download/nginx-1.14.0.tar.gz). So you'll essentially `wget http://nginx.org/download/nginx-1.14.0.tar.gz` then `tar zxvf ...` then move that to `/usr/local/src/nginx` (the location doesn't have to be exist, I just put that for consistency). Many distros have different conventions for enabling modules once they are compiled/installed. Apparently yours have that `modules-enabled` – Danila Vershinin Jan 31 '20 at 11:40
  • Most likely it has `.conf` files with those same `load_module` directives, for each installed module. – Danila Vershinin Jan 31 '20 at 11:40
  • I figured it out. but now I get this error at the end when the script is ran: (I do not want to disable it) – CzipO2 Jan 31 '20 at 15:00
  • ./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre= option. – CzipO2 Jan 31 '20 at 15:00
  • 1
    You will, of course, need any dependency libraries for compiling NGINX. You might want to check [this article](https://www.vultr.com/docs/how-to-compile-nginx-from-source-on-ubuntu-16-04) – Danila Vershinin Jan 31 '20 at 18:08
  • Ok, I managed to install the module " + ngx_http_subs_filter_module was configured" but when I rung nginx -t again it still says "unknown directive "subs_filter_types" in path/vhost" – CzipO2 Feb 04 '20 at 09:49
  • This may mean that you haven't added `load_module modules/..` in `nginx.conf`. – Danila Vershinin Feb 04 '20 at 15:42
  • What file in the module directory should I specify? I have 'config' and 'ngx_http_subs_filter_module.c' for the *.c I get 'invalid ELF header'. Did I add the line correctly? I put it at the beginning outside every bracket. Should I run configure again? – CzipO2 Feb 05 '20 at 15:09
0

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

pavelety
  • 746
  • 6
  • 8