Book Image

Nginx HTTP Server, Third Edition

By : Clement Nedelcu
Book Image

Nginx HTTP Server, Third Edition

By: Clement Nedelcu

Overview of this book

Nginx is a lightweight HTTP server designed for high-traffic websites, with network scalability as the primary objective. With the advent of high speed Internet access, short loading times and fast transfer rates have become a necessity. This free, open source solution will either come as a full replacement of other software such as Apache, or stand in front of your existing infrastructure to improve its overall speed. This book is a detailed guide to setting up Nginx in different ways that correspond to actual production situations: as a standalone server, as a reverse proxy, interacting with applications via FastCGI, and more. In addition, this complete directive reference will be your best friend at all stages of the configuration and maintenance processes. This book is the perfect companion for both Nginx beginners and experienced administrators. For beginners, it will take you through the complete process of setting up this lightweight HTTP server on your system and configuring its various modules so it does exactly what you need quickly and securely. For more experienced administrators, this book provides different approaches that can help you make the most of your current infrastructure. Nginx can be employed in many situations, whether you are looking to construct an entirely new web-serving architecture or simply want to integrate an efficient tool to optimize your site loading speeds.
Table of Contents (17 chapters)
Nginx HTTP Server Third Edition
About the Author
About the Reviewer

Downloading Nginx

This approach to the download process will lead us to discover the various resources at the disposal of server administrators—websites, communities, and wikis - all relating to Nginx. We will also quickly discuss the different version branches available, and eventually select the most appropriate one for our setup.

Websites and resources

Although Nginx is a relatively new and growing project, there are already a good number of resources available on the World Wide Web (WWW) along with an active community of administrators and developers.

The official website,, currently serves as official documentation reference and provides links to download the latest version of the application source code and binaries. A wiki is also available at, which offers a wide selection of additional resources, such as installation guides for various operating systems, tutorials related to the different modules of Nginx, and more.

There are several ways to get help in case you should need it. If you have a specific question, you may want to try posting on the Nginx forum: An active community of users will answer your questions in no time. Additionally, the Nginx mailing list, which is relayed on the Nginx forum, will also prove to be an excellent resource for any question you may have. If you need direct assistance, there is always a group of regulars helping each other out on the IRC channel #Nginx on

Another interesting source of information is the blogosphere. A simple query on your favorite search engine should return a good number of blog articles documenting Nginx, its configuration, and its modules.

Personal websites and blogs documenting Nginx

It's now time to head over to the official website and get started with downloading the source code to compile and install Nginx. Before you do so, let's take a quick look at a summary of the available versions and features that come with them.

Version branches

Igor Sysoev, a talented Russian developer and server administrator, initiated the project back in 2002. Between the first release in 2004 and the current version, the market share of Nginx has been growing steadily. It now serves nearly 15 percent of websites on the Internet, according to a October 2015 survey. The features are plenty and render the application both powerful and flexible at the same time.

There are currently three version branches of the project:

  • Stable version: This version is usually recommended, as it is approved by both developers and users, but is usually a little behind the mainline version in terms of bugfixes and features.

  • Mainline version: This is the latest version available for download and comes with the newest developments and bug fixes. It was formerly known as the development version. Although it is generally solid enough to be installed on production servers, there is a tiny chance that you will run into the occasional bug. Thus, if you favor stability over novelty, going for the stable version is recommended.

  • Legacy version: If, for some reason, you are interested in looking at the older versions, you will find them in the download area at

A recurring question regarding mainline versions is, are they stable enough to be used on production servers? Cliff Wells, original founder and maintainer of the wiki, believes so: I generally use and recommend the latest development version. It's only bitten me once! Early adopters rarely report critical problems. It is up to you to select the version you will be using on your server, knowing that the instructions given in this book should be valid regardless of the release, as the Nginx developers have decided to maintain overall backward compatibility in new versions. You can find more information on version changes, new additions, and bug fixes in the dedicated change log page on the official website.


As of the stable version 1.8.0, Nginx offers an impressive variety of features, which, contrary to what the title of this book indicates, are not all related to serving HTTP content. Here is a list of the main features of the web branch, quoted from the official website

  • Serving static and index files; autoindexing; open file descriptor cache; accelerated reverse proxying with caching; load balancing and fault tolerance.

  • Accelerated support with caching of FastCGI, uwsgi, Simple Common Gateway Interface (SCGI), and memcached servers; load balancing and fault tolerance; modular architecture. Filters include gzipping, byte ranges, chunked responses, XSLT, SSI, and image transformation filter. Multiple SSI inclusions within a single page can be processed in parallel if they are handled by proxied or FastCGI/uwsgi/SCGI servers.

  • SSL and TLS SNI support.

Nginx can also be used as a mail proxy server, although this aspect is not closely documented in the book:

  • User redirection to IMAP/POP3 backend using an external HTTP authentication server

  • User authentication using an external HTTP authentication server and connection redirection to an internal SMTP backend

  • Authentication methods:




  • SSL support

  • STARTTLS and STLS support

Nginx is compatible with most computer architectures and operating systems, including Windows, Linux, Mac OS, FreeBSD, and Solaris. The application runs well on 32- and 64-bit architectures.

Downloading and extracting

Once you have made your choice about which version you will be using, head over to and find the URL of the file you wish to download. Position yourself in your home directory, which will contain the source code to be compiled, and download the file using wget:

[[email protected] ~]$ mkdir src && cd src
[[email protected] src]$ wget

We will be using version 1.8.0, the latest stable version as of April, 2015. Once downloaded, extract the archive contents in the current folder:

[[email protected] src]$ tar zxf nginx-1.8.0.tar.gz

You have successfully downloaded and extracted Nginx. Now, the next step will be to configure the compilation process in order to obtain a binary that perfectly fits your operating system.