It is a well-known fact that the market of web servers has a long-established leader: Apache. According to recent surveys, as of October 2009 over 45 percent of the World Wide Web is served by this fifteen years old open source application. However, for the past few months the same reports reveal the rise of a new competitor: Nginx, a lightweight HTTP server originating from Russia— pronounced "engine X". There have been many interrogations surrounding the pronounced newborn. Why has the blogosphere become so effervescent about it? What is the reason causing so many server administrators to switch to Nginx since the beginning of year 2009? Is this apparently tiny piece of software mature enough to run my high-traffic website?
To begin with, Nginx is not as young as one might think. Originally started in 2002, the project was first carried out by a standalone developer, Igor Sysoev, for the needs of an extremely high-traffic Russian website, namely Rambler, which received as of September 2008 over 500 million HTTP requests per day. The application is now used to serve some of the most popular websites on the Web such as WordPress, Hulu, SourceForge, and many more. Nginx has proven to be a very efficient, lightweight yet powerful web server. Along the chapters of this book, you will discover the many features of Nginx and progressively understand why so many administrators have decided to place their trust in this new HTTP server, often at the expense of Apache.
There are many aspects in which Nginx is more efficient than its competitors. First and foremost, speed. Making use of asynchronous sockets, Nginx does not spawn as many times as it receives requests. One process per core suffices to handle thousands of connections, allowing for a much lighter CPU load and memory consumption. Secondly, ease of use—configuration files are much simpler to read and tweak than with other web server solutions such as Apache. A couple of lines are enough to set up a complete virtual host configuration. Last but not least, modularity. Not only is Nginx a completely open source project released under a BSD-like license, but it also comes with a powerful plug-in system—referred to as "modules". A large variety of modules are included with the original distribution archive, and many third-party ones can be downloaded online. All in all, Nginx combines speed, efficiency, and power, providing you the perfect ingredients for a successful web server; it appears to be the best Apache alternative as of today.
Although Nginx is available for Windows since version 0.7.52, it is common knowledge that Linux distributions are preferred for hosting production sites. During the various processes described in this book, we will thus assume that you are hosting your website on a Linux operating system such as Debian, Fedora, CentOS, Mandriva, or other well-known distributions.
Chapter 1, Preparing your Work Environment provides a basic approach of the Linux command-line environment that we will be using throughout this book.
Chapter 2, Downloading and Installing Nginx guides you through the setup process, by downloading and installing Nginx as well as its prerequisites.
Chapter 3, Basic Nginx Configuration helps you discover the fundamentals of Nginx configuration and set up the Core module.
Chapter 4, HTTP Configuration details the HTTP Core module which contains most of the major configuration sections and directives.
Chapter 5, Module Configuration helps you discover the many first-party modules of Nginx among which are the Rewrite and the SSI modules.
Chapter 6, PHP and Python with Nginx explains how to set up PHP and other third- party applications (if you are interested in serving dynamic websites) to work together with Nginx via FastCGI.
Chapter 7, Apache and Nginx Together teaches you to set up Nginx as reverse proxy server working together with Apache.
Chapter 8, From Apache to Nginx provides a detailed guide to switching from Apache to Nginx.
Appendix A, Directive Index lists and describes all configuration directives, sorted alphabetically. Module directives are also described in their respective chapters too.
Appendix B, Module reference lists available modules.
Appendix C, Troubleshooting discusses the most common issues that administrators face when they configure Nginx.
Nginx is free and open source software running under various operating systems— Linux-based, Mac OS, Windows operating systems, and many more. As such, there is no real requirement in terms of software. Nevertheless in this book and particularly in the first two chapters we will be working in a Linux environment, so running a Linux-based operating system would be a plus. Prerequisites for compiling the application are further detailed in Chapter 2.
This book is a perfect companion for both Nginx beginners and experienced administrators. For the former, it will take you through the complete process of setting up this lightweight HTTP server on your system and configuring its various modules to get it to do exactly what you need, in a fast and secure way. For the latter, it provides different angles of approach that can help you make the most of your current infrastructure. As the book progresses, it provides a complete reference to all the modules and directives of Nginx. It will explain how to replace your existing server with Nginx or configure Nginx to work as a frontend for your existing server.