Compiling Nginx from source on Ubuntu - April 2016 Update
Compiling Nginx, like other open source projects, tends to be a bit of a moving target. New versions are regularly released, dependent libraries are updated, and new modules become available over time. SPDY has been retired in favor of HTTP v2, and that changes is reflected in the latest build target for Nginx.
Getting the Source
The latest Mainline version of Nginx, 1.9.14, and the latest Stable version, 1.8.1, as well as older versions, can be downloaded from the Nginx web site.
Pick the source version to build and download the archive, then go to the command line. For my purposes, I like to use the Mainline version, so I will be downloading 1.9.14.
Nginx and its dependencies offer checksum verification using hashes that you can download from their respective download sites. These checksums allow you to verify that the source code you have downloaded is legitimate. See how to verify checksums for downloaded files.
Nginx depends on a few external modules that you will need to download from source if you want to support the features those modules enable.
- zlib - Used by Nginx for over the wire compression using Gzip. Nginx supports negotiated compression with browsers that support compression to minimize bandwidth usage.
- PCRE - Used by Nginx Core and Rewrite and provides Nginx support for Regular Expressions
- OpenSSL - Used to enable SSL/TLS encryption support on Nginx. OpenSSL has suffered a number of exploits in recent years and some developers have started using LibreSSL instead.
- LibreSSL - Forked from OpenSSL in 2014 with goals of modernizing the codebase and improving security. Alternative SSL/TLS implemenation for Nginx.
Download the latest stable version and extract the archives into their respective folders. When I am building from source, I like to start in my home folder and create an nginx folder as the root of my build, copying all of the source tarballs I have downloaded into that folder before extracting them.
$ mkdir nginx $ cp *.tar.gz nginx $ cd nginx $ tar -zxvf
I then extract the other tarballs with tar -zxvf filename so I end up with a folder structure like:
./nginx nginx-1.9.14/ pcre-8.38/ openssl-1.0.2g/ zlib-1.2.8/
Then I move into the nginx source folder and configure the installer script:
$ cd nginx-1.9.14 $ ./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-pcre=../pcre-8.38 --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-1.0.2g --with-http_ssl_module --with-http_v2_module
When the configure program finishes, you will get a summary of the install configuration:
Configuration summary + using PCRE library: ../pcre-8.38 + using OpenSSL library: ../openssl-1.0.2g + md5: using OpenSSL library + sha1: using OpenSSL library + using zlib library: ../zlib-1.2.8 nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/nginx" nginx modules path: "/usr/local/nginx/modules" nginx configuration prefix: "/usr/local/nginx" nginx configuration file: "/usr/local/nginx/nginx.conf" nginx pid file: "/usr/local/nginx/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp"
You can then run make and make install to install the compiled binaries:
$ make $ make install
The make command make take a little while to run, depending on the hardware configuration of your install target. Once you run make install, your installation will be done.