Mastering NGINX

Book Description

Written for experienced systems administrators and engineers, this book teaches you from scratch how to configure Nginx for any situation. Step-by-step instructions and real-world code snippets clarify even the most complex areas.

  • An in-depth configuration guide to help you understand how to best configure NGINX for any situation
  • Includes useful code samples to help you integrate NGINX into your application architecture
  • Full of example configuration snippets, best-practice descriptions, and reference tables for each directive

In Detail

NGINX is a high-performance HTTP server and mail proxy designed to use very few system resources. With the many tutorials and example configurations floating around the Web, it is difficult to know how to properly configure NGINX to meet your expectations.

"Mastering Nginx" will serve to clarify the murky waters of NGINX configuration, helping you learn how to tune NGINX for various situations, what some of the more obscure configuration directives do, and how to design a decent configuration to match your needs.

Beginning with an overview of compiling NGINX and describing its basic configuration file format, this guide next takes you on a tour of NGINX's modules.

From the unique mail module to the upstream module, this book explores the various possibilities of using NGINX as a reverse proxy. The multiple HTTP modules are explained, and the book rounds off the tour with a discussion of troubleshooting.

"Mastering Nginx" will explain all aspects of configuring NGINX to help solve your hosting problems.

Table of Contents

  1. Mastering NGINX
    1. Table of Contents
    2. Mastering NGINX
    3. Credits
    4. About the Author
    5. About the Reviewers
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Installing NGINX and Third-Party Modules
      1. Installing NGINX using a package manager
        1. CentOS
        2. Debian
      2. Installing NGINX from source
        1. Preparing a build environment
        2. Compiling from source
          1. Table: Common configure options
          2. Table: Configure options for optimization
      3. Configuring for web or mail service
        1. Configure options for a mail proxy
          1. Table: Mail configure options
        2. Configure the options to specify paths
          1. Table: HTTP configure options
      4. Enabling various modules
        1. Table: HTTP module configure options
        2. Disabling unused modules
          1. Table: Disable configure options
      5. Finding and installing third-party modules
      6. Putting it all together
      7. Summary
    9. 2. A Configuration Guide
      1. The basic configuration format
      2. NGINX global configuration parameters
        1. Table: Global configuration directives
      3. Using include files
      4. The HTTP server section
        1. Client directives
          1. Table: HTTP client directives
        2. File I/O directives
          1. Table: HTTP file I/O directives
        3. Hash directives
          1. Table: HTTP hash directives
        4. Socket directives
          1. Table: HTTP socket directives
        5. Sample configuration
      5. The virtual server section
        1. Table: listen parameters
      6. Locations – where, when, and how
        1. Table: Location modifiers
        2. Table: Location-only directives
      7. The mail server section
        1. Table: Mail module directives
        2. Table: Mail SSL directives
      8. Full sample configuration
      9. Summary
    10. 3. Using the Mail Module
      1. Basic proxy service
        1. POP3 service
        2. IMAP service
        3. SMTP service
        4. Using SSL/TLS
        5. Complete mail example
      2. Authentication service
      3. Combining with memcached
      4. Interpreting log files
      5. Operating system limits
      6. Summary
    11. 4. NGINX as a Reverse Proxy
      1. Introduction to reverse proxying
        1. The proxy module
          1. Table: Proxy module directives
          2. Legacy servers with cookies
        2. The upstream module
          1. Table: Upstream module directives
          2. Keepalive connections
          3. Load-balancing algorithms
      2. Types of upstream servers
        1. Single upstream server
        2. Multiple upstream servers
        3. Non-HTTP upstream servers
          1. Memcached upstream servers
          2. FastCGI upstream servers
          3. SCGI upstream servers
          4. uWSGI upstream servers
      3. Converting an "if"-fy configuration to a more modern interpretation
      4. Using error documents to handle upstream problems
      5. Determining the client's real IP address
      6. Summary
    12. 5. Reverse Proxy Advanced Topics
      1. Security through separation
        1. Encrypting traffic with SSL
        2. Authenticating clients using SSL
        3. Blocking traffic based on originating IP address
      2. Isolating application components for scalability
      3. Reverse proxy performance tuning
        1. Buffering
          1. Table: Proxy module buffering directives
        2. Caching
          1. Table: Proxy module caching directives
          2. Storing
        3. Compressing
          1. Table: Gzip module directives
      4. Summary
    13. 6. The NGINX HTTP Server
      1. NGINX's architecture
      2. The HTTP core module
        1. The server
          1. Table: HTTP server directives
        2. Logging
          1. Table: HTTP logging directives
          2. Table: Log format variables
        3. Finding files
          1. Table: HTTP file-path directives
        4. Name resolution
          1. Table: Name resolution directives
        5. Client interaction
          1. Table: HTTP client interaction directives
      3. Using limits to prevent abuse
        1. Table: HTTP limits directives
      4. Restricting access
        1. Table: HTTP access module directives
      5. Streaming media files
        1. Table: HTTP streaming directives
      6. Predefined variables
        1. Table: HTTP variables
      7. Using NGINX with PHP-FPM
        1. Table: FastCGI directives
        2. An example Drupal configuration
      8. Wiring NGINX and uWSGI together
        1. An example Django configuration
      9. Summary
    14. 7. NGINX for the Developer
      1. Caching integration
        1. No application caching
        2. Caching in the database
          1. Table: Memcached module directives
        3. Caching in the filesystem
          1. Table: Header modifying directives
      2. Changing content on-the-fly
        1. The addition module
          1. Table: HTTP addition module directives
        2. The sub module
          1. Table: HTTP sub module directives
        3. The xslt module
          1. Table: HTTP XSLT module directives
      3. Using Server Side Includes
        1. Table: Server Side Includes directives
        2. Table: Server Side Includes commands
      4. Decision-making in NGINX
        1. Table: Perl module directives
      5. Creating a secure link
      6. Generating images
        1. Table: Image filter directives
      7. Tracking website visitors
        1. Table: UserID module directives
      8. Preventing inadvertent code execution
      9. Summary
    15. 8. Troubleshooting Techniques
      1. Analyzing log files
        1. Error log file formats
        2. Error log file entry examples
      2. Configuring advanced logging
        1. Debug logging
          1. Switching binaries at runtime
        2. Using access logs for debugging
      3. Common configuration errors
        1. Using if instead of try_files
        2. Using if as a hostname switch
        3. Not using the server context to best effect
      4. Operating system limits
        1. File descriptor limits
        2. Network limits
      5. Performance problems
      6. Using the Stub Status module
      7. Summary
    16. A. Directive Reference
      1. Table: Directive reference
    17. B. Rewrite Rule Guide
      1. Introducing the rewrite module
        1. Table: Rewrite module directives
      2. Creating new rewrite rules
      3. Translating from Apache
        1. Rule #1: Replace directory and file existence checks with try_files
        2. Rule #2: Replace matches against REQUEST_URI with a location
        3. Rule #3: Replace matches against HTTP_HOST with a server
        4. Rule #4: Replace RewriteCond with if for variable checks
      4. Summary
    18. C. The NGINX Community
      1. Mailing list
      2. IRC channel
      3. Web resources
      4. Writing a good bug report
      5. Summary
    19. D. Persisting Solaris Network Tunings
    20. Index

Product Information

  • Title: Mastering NGINX
  • Author(s): Dimitri Aivaliotis
  • Release date: March 2013
  • Publisher(s): Packt Publishing
  • ISBN: 9781849517447