Nginx Dynamic Modules

In version 1.9.11 , nginx introduced a new feature “Dynamic modules”.  With dynamic modules, you can optionally load separate shared object files at runtime as modules – both third-party modules and some native NGINX modules.

In earlier versions of nginx, modules are not dynamically loadable, so they must be selected and compiled into the core software.  The module was loaded with NGINX every time, whether you need it or not. For many users, this made Nginx much less flexible, especially for users who are not comfortable maintaining their own compiled software outside of their distribution’s conventional packaging system. While distributions’ packages tend to include the most commonly used modules, if you require a non-standard module , you will have to build the server from source yourself .

In the first release of nginx dynamic module, we still need to recompile nginx also along with the needed modules , but we can decide if we want to enable it on runtime. This is a good start , now  users can compile nginx with all required modules and enable it on runtime whenever its needed. But in future , Nginx.org  will  add the ability to compile modules after the NGINX binary has been compiled. This will make nginx modules portable . In near future we can expect OS packages for each nginx module , which can be loaded on runtime. I am sure this will enhance the growth and  popularity of nginx.

How to compile nginx with Dynamic modules?

Let us see how to build and install nginx  with dynamic modules enabled, on a Centos machine. We will download nginx source from nginx.org and build it with geoip module loaded dynamically

First we will install geoip library on the machine

If configure script is successful, you will see following on the screen

You can see that modules will be stored under the folder ”

Now build and install nginx using following commands

If everything goes well you should see nginx installed at

and geoip module at

Now we can load this module on Runtime , by adding following line in the nginx.conf file

Make sure you add this line outside “http” block and reload nginx once done.

So we have loaded this module dynamically, and we can disable this module at anytime by commenting that line and reloading nginx.

The Future of Dynamic Modules

As of now this feature is not of much use as we need to recompile nginx to
create the dynamic modules. But in future , Nginx.org  will  add the ability to compile modules after the NGINX binary has been compiled. This will make nginx modules portable . In near future we can expect OS packages for each nginx module , which can be loaded on runtime. Am sure this will enhance the increasing  popularity of nginx.

Leave a Reply

Your email address will not be published. Required fields are marked *