Book Image

Nginx 1 Web Server Implementation Cookbook

By : Dipankar Sarkar
Book Image

Nginx 1 Web Server Implementation Cookbook

By: Dipankar Sarkar

Overview of this book

<p>Nginx is an open source high-performance web server, which has gained quite some popularity recently. Due to its modular architecture and small footprint, it has been the default choice for a lot of smaller Web 2.0 companies for use as a load-balancing proxy server. It supports most of the existing back-end web protocols like FCGI, WSGI, and SCGI. This book is for you if you want to have in-depth knowledge of the Nginx server.<br /><br /><i>Nginx 1 Web Server Implementation Cookbook</i> covers the whole range of techniques that would prove useful for you in setting up a very effective web application with the Nginx web server. It has recipes for lesser-known applications of Nginx like a mail proxy server, streaming of video files, image resizing on the fly, and much more.<br /><br />The first chapter of the book covers the basics that would be useful for anyone who is starting with Nginx. Each recipe is designed to be independent of the others.<br /><br />The book has recipes based on broad areas such as core, logging, rewrites, security, and others. We look at ways to optimize your Nginx setup, setting up your WordPress blog, blocking bots that post spam on your site, setting up monitoring using munin, and much more.</p> <p>Nginx 1 Web Server Implementation Cookbook makes your entry into the Nginx world easy with step-by-step recipes for nearly all the tasks necessary to run your own web application.</p>
Table of Contents (17 chapters)
Nginx 1 Web Server Implementation Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Installing new modules and compiling Nginx


Today, most softwares are designed to be modular and extensible. Nginx, with its great community, has an amazing set of modules out there that lets it do some pretty interesting things. Although most operating system distributions have Nginx binaries in their repositories, it is a necessary skill to be able to compile new, bleeding edge modules, and try them out. Now we will outline how one can go about compiling and installing Nginx with its numerous third-party modules.

How to do it...

  1. The first step is to get the latest Nginx distribution, so that you are in sync with the security and performance patches (http://sysoev.ru/nginx/nginx-0.7.67.tar.gz). Do note that you will require sudo or root access to do some of the installation steps going ahead.

  2. Un-tar the Nginx source code. This is simple, you will need to enter the following command:

    tar -xvzf nginx-0.7.67.tar.gz
    
  3. Go into the directory and configure it. This is essential, as here you can enable and disable the core modules that already come with Nginx. Following is a sample configure command:

    ./configure -–with-debug \
    --with-http_ssl_module \
    --with-http_realip_module \ 
    --with-http_ssl_module \ 
    --with-http_perl_module \ 
    --with-http_stub_status_module
    

    You can figure out more about what other modules and configuration flags use:

    ./configure -–help
    
  4. If you get an error, then you will need to install the build dependencies, depending on your system. For example, if you are running a Debian based system, you can enter the following command:

    apt-get build-dep nginx
    

    This will install all the required build dependencies, like PCRE and TLS libraries.

  5. After this, you can simply go ahead and build it:

    sudo make install
    
  6. This was the plain vanilla installation! If you want to install some new modules, we take the example of the HTTP subscribe-publish module:

  7. Download your module (http://pushmodule.slact.net/downloads/nginx_http_push_module-0.692.tar.gz).

  8. Un-tar it at a certain location:/path/to/module.

  9. Reconfigure Nginx installation:

    ./configure ..... --add-module=/path/to/module
    

    The important part is to point the –add-module flag to the right module path. The rest is handled by the Nginx configuration script.

  10. You can continue to build and install Nginx as shown in step 5.

    sudo make install
    

If you have followed steps 1 to 10, it will be really easy for you to install any Nginx module.

There's more...

If you want to check that the module is installed correctly, you can enter the following command:

nginx -V 

A sample output is something as shown in the following screenshot:

This basically gives you the compilation flags that were used to install this particular binary of Nginx, indirectly listing the various modules that were compiled into it.