Today, most softwares are designed to be modular and extensible. Nginx, with its great community, has an amazing set of modules out there that lets it do some pretty interesting things. Although most operating system distributions have Nginx binaries in their repositories, it is a necessary skill to be able to compile new, bleeding edge modules, and try them out. Now we will outline how one can go about compiling and installing Nginx with its numerous third-party modules.
The first step is to get the latest Nginx distribution, so that you are in sync with the security and performance patches (http://sysoev.ru/nginx/nginx-0.7.67.tar.gz). Do note that you will require sudo or root access to do some of the installation steps going ahead.
Un-tar the Nginx source code. This is simple, you will need to enter the following command:
tar -xvzf nginx-0.7.67.tar.gz
Go into the directory and configure it. This is essential, as here you can enable and disable the core modules that already come with Nginx. Following is a sample configure command:
./configure -–with-debug \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_ssl_module \ --with-http_perl_module \ --with-http_stub_status_module
You can figure out more about what other modules and configuration flags use:
./configure -–help
If you get an error, then you will need to install the build dependencies, depending on your system. For example, if you are running a Debian based system, you can enter the following command:
apt-get build-dep nginx
This will install all the required build dependencies, like PCRE and TLS libraries.
After this, you can simply go ahead and build it:
sudo make install
This was the plain vanilla installation! If you want to install some new modules, we take the example of the HTTP subscribe-publish module:
Download your module (http://pushmodule.slact.net/downloads/nginx_http_push_module-0.692.tar.gz).
Un-tar it at a certain location:
/path/to/module
.Reconfigure Nginx installation:
./configure ..... --add-module=/path/to/module
The important part is to point the
–add-module
flag to the right module path. The rest is handled by the Nginx configuration script.You can continue to build and install Nginx as shown in step 5.
sudo make install
If you have followed steps 1 to 10, it will be really easy for you to install any Nginx module.
If you want to check that the module is installed correctly, you can enter the following command:
nginx -V
A sample output is something as shown in the following screenshot:
This basically gives you the compilation flags that were used to install this particular binary of Nginx, indirectly listing the various modules that were compiled into it.