0

My nginx version is nginx/1.18.0 (Ubuntu). I want to install a dynamic module on the server https://www.nginx.com/resources/wiki/modules/headers_more/. The official documentation states:

"Grab the nginx source code from nginx.org, for example, the version 1.17.8 (see nginx compatibility), and then build the source with this module:"


 wget 'http://nginx.org/download/nginx-1.17.8.tar.gz'
 tar -xzvf nginx-1.17.8.tar.gz
 cd nginx-1.17.8/

 # Here we assume you would install you nginx under /opt/nginx/.
 ./configure --prefix=/opt/nginx \
     --add-module=/path/to/headers-more-nginx-module

 make
 make install

I have already installed 1.18.0. version and I do not need to wget and unzip a new nginx.

How to install this dynamic module? Should I just type ./configure? If so, what path/to should I pass in the code?

  • If you have already installed nginX from a binary package - remove that package first, then download the source code for your preferred nginX version (e.g. 1.18.0), download the source code for your module, and then compile them both (nginX and the module) according to their manuals. – IVO GELOV Mar 03 '23 at 08:08

3 Answers3

1

Looks like you wget nginx v1.17.8. This is not going to work. You should get your current nginx version.

And then you need to get original nginx arguments with this command, nginx -V

Copy the output of that command to a text editor. And do following,

  1. Add ./configure to the beginning of configure arguments.
  2. Remove all dynamic modules. These are the arguments that begin with --add-module=
  3. Add new argument --sbin-path=/usr/sbin/nginx towards the beginning.
  4. Add new argument --add-module=/path/to/module/ towards the beginning.

Now copy everything from text file and execute in the nginx source directory (downloaded).

Now stop Nginx and do make and make install

Start nginx. Try it.

These instructions were adapted from Install Naxsi Dynamic Module for nginx!

Naxsi is a dynamic module and you can adapt the instructions to install any nginx dynamic module.

0

If you want only make dynamic module without install nginx, make this:

wget 'http://nginx.org/download/nginx-1.17.8.tar.gz'
tar -xzvf nginx-1.17.8.tar.gz
cd nginx-1.17.8/

./configure ...args... --add-module=/path/to/headers-more-nginx-module
make

Don't do make install Copy compiled module from dir nginx-1.17.8/objs to the directory from which it will be loaded, like:

cp ./objs/ngx_http_headers_more_filter_module.so /etc/nginx/modules/

and load from nginx.conf

load_module modules/ngx_http_headers_more_filter_module.so;
nginx -t && nginx -s reload
yuppi
  • 107
  • 3
0

You could get the source of nginx that have been use to build the version packaged for your ubuntu (or debian derivative) version.

via the nginx-dev package ( link for kinetic )

which would put the source in /usr/share/nginx/src

As mentioned in another answer you would need to run /usr/sbin/nginx -V to get the configure script options that have been used.

then run the configure script with a subset of the options you have extracted above, add --add-module=$PATH_TO_YOUR_MODULE then run make modules or make -f objs/Makefile modules to only build the targeted module. then you compiled module would be in the objs directory

Example:

# assuming you are running from the module directory
export PATH_TO_YOUR_MODULE=$PWD
apt-get -qy update
apt-get -qy install build-essential nginx-dev
cp -R /usr/share/nginx/src /tmp/nginx-src
pushd /tmp/nginx-src
CONFIGURE_CMD="./configure $(nginx -V 2>&1 | grep 'configure arguments: ' | sed 's/configure arguments: //;s/--with-http\S* //g;s/--with-stream\S*//g;s/--with-mail\S* //g') --add-dynamic-module=\"${PATH_TO_YOUR_MODULE}\""
eval "${CONFIGURE_CMD}"
make -f objs/Makefile modules
popd
cp /tmp/nginx-src/objs/your-module.so .
dvhh
  • 4,724
  • 27
  • 33