Compile Nginx

There are two possible ways to install nginx: you can download from the official website a pre-bluit package or you can decide to compile it by yourself and configure it as you wish. I strongly suggest first time users to use the prebuild package. However, building it by yourself could be a chance to learn about compiling and nginx 3rd party modules.

This is the only guide available on the internet that have been heavy tested, do not trust other methods because this one JUST WORKS!>

Responsive image

0. Add Nginx Signing Key & Modify Sources.list

Download the key and add it to apt program keyring.


sudo apt-key add nginx_signing.key

nano /etc/apt/sources.list

Add the following code at the end of the file in two different rows. Substitute "codename" with the debian distribution you have installed like "wheezy" or "Jessie".

deb codename nginx

deb-src codename nginx

If you want to install the mainline version append instead the following code.

deb codename nginx

deb-src codename nginx

For ubuntu place

deb codename nginx

deb-src codename nginx

1. Install Nginx

With this passage you install nginx with apt-get in order to get int.d and pid files. If you decide to skip this passage you will need to crate that files yourself.

sudo apt-get update

sudo apt-get install nginx

Now stop and remove nginx leaving only init.d and pid files.

sudo service nginx stop

sudo apt-get remove nginx

sudo apt-get remove nginx-common

Get rid of nginx configuration.

sudo rm -r /etc/nginx

2. Download Nginx Source & Install Dependencies

cd /tmp


Extract it.

tar -zxvf nginx-1.9.x.tar.gz

Refresh the repositorie.

sudo apt-get update

The next command will install the required dependencies.

sudo apt-get build-dep nginx

4. Configure the Binaries

Enter the folder containing the package downloded.

cd nginx-1.9.x

Type the following command in one row. Check that most of the code output generated by ./configure command gives "found" values. If not try to use the sudo before the command or check again your configuration for errors.

./configure ...

As there are many configuration arguments possible I suggest you to look at Nginx Docs in order to best fit your needs. If you include Naxsi rules I suggest you to put that module at the top of the ./configure command, for more info Naxsi wiki.

After having configured the installation is time to compile the package with the following command make; and install it make install.

Lastly you need to unmask the installed service.

sudo systemctl unmask nginx

5. Configure the Extra Binaries

Download naxsi


tar -zxvf 0.54.tar.gz

Include naxsi in the ./configure file


Download zlib


tar -zxvf zlib-1.2.8.tar.gz

Include naxsi in the ./configure file


6. Enjoy the Power of Nginx :)

This article was last updatated the 12/3/16