This page will show you how to add module to an existent nginx installation
If you want to add another module to an existing installation, you need to build it against the source as dynamic module (.so) and add it to your configuration.
Optional
If you have installed Nginx from a package, you may need to install them
yum install -y redhat-rpm-config openssl-devel gc gcc gcc-c++ pcre-devel zlib-devel make wget libxml2-devel libxslt-devel gd-devel perl-ExtUtils-Embed GeoIP-devel gperftools gperftools-devel libatomic_ops-devel perl-ExtUtils-Embed
nginx -v
wget https://nginx.org/download/nginx-${nginx_version}.tar.gz
# example
wget https://nginx.org/download/nginx-1.16.1.tar.gz
tar zxf nginx-1.16.1.tar.gz
Install the dependencies of your module
Example
yum install -y gcc-c++ pcre-devel zlib-devel make unzip libuuid-devel
Example :
wget https://github.com/apache/incubator-pagespeed-ngx/archive/1.13.35.2-stable.zip
unzip 1.13.35.2-stable.zip
# psol page speed dependency download
cd incubator-pagespeed-ngx-1.13.35.2
wget https://dl.google.com/dl/page-speed/psol/1.13.35.2-x64.tar.gz
tar zxf 1.13.35.2-x64.tar.gz
nginx -V
# or
nginx -V 2>&1 | grep 'configure arguments' | cut --delimiter ':' --fields=2-
cd nginx
./configure \
CONFIGURE_ARGUMENTS \ # should be replace with the output of nginx -V
--add-dynamic-module=/path/to/module
cd nginx
IFS=$'\t'; ./configure \
--add-dynamic-module=../incubator-pagespeed-ngx-1.13.35.2 \
$(nginx -V 2>&1 | grep 'configure arguments' | cut --delimiter ':' --fields=2- | sed $'s/ --/\t--/g' | sed $'s/\t--param/ --param/g' | tr -d "'" | cut -c2- ) \
> configure-stdout-ansible-cmd.log 2>&1
make
# or with two process
make -j 2
Copy the shared library create into the module path.
nginx -V 2>&1 | grep 'configure arguments' | sed 's/--/\n--/g' | grep prefix
--prefix=/usr/share/nginx
cp ./objs/dynamic_library.so /usr/share/nginx/modules
# with pagespeed
cp ./objs/ngx_pagespeed.so /usr/share/nginx/modules
load_module "modules/dynamic_library.so";
# with pagespeed
load_module "modules/ngx_pagespeed.so";
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
systemctl reload nginx
# FYI: may be also restart ?
systemctl restart nginx
There is a lot of chance that the configuration arguments passed to the configure steps are not the good one.
nginx: [emerg] dlopen() "/usr/share/nginx/modules/ngx_pagespeed.so" failed (/usr/share/nginx/modules/ngx_pagespeed.so: cannot e...ginx.conf:11
selinux may unauthorize the loading of the library.