Compiling NGINX From Source [NGINX-Copied]

Note

These directions are way out of date. Do not use these! I have since switched to a different process or tool since writing this particular article, but keeping it up for posterities sake, until I can properly replace it.

What have I changed to you ask? Anything building I’ve tried switching over to Ansible to handle in a much more programatic way. Others might be tools that I just don’t use at all anymore, due to changing DNS hosts.

The way listed here uses apt-get to our advantage. By adding the NGINX PPA repo, we get a baseline of required files, configuration files, and other things that make this much easier for us all!

Add NGINX PPA

For the $nginx variable at the end of the first code line, replace it with either stable for their Stable line or development for their Mainline.

Note

Mainline is what they consider their “beta” line. Stable being their, well, “stable” line.

sudo add-apt-repository ppa:nginx/$nginx

Then, go in and remove the comment from the deb-src line inside the apt/sources.list.d/nginx.list file. The file most likely will be named something else.

Then update apt-get.

sudo apt-get update

Download Source Packages

Prerequisites

First, we install the pre-requisites. AKA the package creation tools. This helps in building from source using apt.

sudo apt-get install dpkg-dev -y

Build Directory

The directory /opt/rebuildnginx is simply a potential, central location for all of the building files that we are wanting to use. You can stick it anywhere you want, name it anything you want.

sudo mkdir /opt/rebuildnginx
cd /opt/rebuildnginx

Source Files Download

Next, running apt-get source rather than apt-get install installs the source files for the program you’ve listed.

sudo apt-get source nginx

Install Build Dependencies

sudo apt-get build-dep nginx

If the current, main NGINX build doesn’t have the specific modules that you are needing, you can add them into a specific file inside the build directory.

The detailed instructions for that specialized need is at ServersForHackers.com

Compile and Install

cd /opt/rebuildnginx/nginx-{release}
sudo dpkg-buildpackage -uc -b

This will take around a few minutes.

Install NGINX

Once the build is complete, we’ll find a bunch of .deb files added in /opt/rebuildnginx. We can use these to install NGINX.

The full package, quite aptly, has the most pre-built modules. So, if thats what you’re needing, concentrate on those files.

Next, you’ll want to check if you’re on 64bit or otherwise. If you’re on 64bit, most likely you wanna use amd64 files. Also, the dbg is specifically for debugging tools.

Do you have the file you wanna use? Lets install it then!

sudo dpkg --install nginx-full_{ release }+trusty0_amd64.deb

Now, you can run nginx -V (capital V) and it’ll show you the flags and modules and whatnot compiled with NGINX.

Block NGINX from Auto-Update

Next, mark NGINX to be blocked from further apt-get updates, as this potentially will remove the modules you added.

sudo dpkg --get-selections | grep nginx

and for every nginx component listed run:

sudo apt-mark hold {component}

And from now on, make sure to watch NGINXs opensource web page for more updates, and perform the same steps again.

[NGINX-Copied]

These instructions are happily borrowed from ServersForHackers.com