O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering NGINX - Second Edition

Book Description

An in-depth guide to configuring NGINX for your everyday server needs

About This Book

  • Get tips, tricks, and master insight to help you configure NGINX for any server situation
  • Integrate NGINX into your applications architecture with is, using hands-on guidance and practical code samples that are free to use
  • Troubleshoot configuration problems before and as they arise, for a seamless NGINX server experience

Who This Book Is For

This book is for system administrators and engineers who want to personalize NGINX, and design a robust configuration module to solve their hosting problems. Some knowledge of NGINX is a plus, but is not a prerequisite.

What You Will Learn

  • Compile the right third-party module to meet your needs
  • Write an authentication server to use with the mail proxy module
  • Create your own SSL certificates to encrypt connections
  • Use try_files to solve your file-existence check problems
  • Cache and compress responses to get speedier user interaction
  • Integrate popular PHP frameworks with the FastCGI module
  • Construct useful logging configurations

In Detail

NGINX is a high-performance HTTP server and mail proxy designed to use very few system resources. But despite its power it is often a challenge to properly configure NGINX to meet your expectations. Mastering Nginx is the solution – an insider’s guide that will clarify the murky waters of NGINX’s configuration. Tune NGINX for various situations, improve your NGINX experience with some of the more obscure configuration directives, and discover how to design and personalize a configuration to match your needs.

To begin with, quickly brush up on installing and setting up the NGINX server on the OS and its integration with third-party modules. From here, move on to explain NGINX's mail proxy module and its authentication, and reverse proxy to solve scaling issues. Then see how to integrate NGINX with your applications to perform tasks.

The latter part of the book focuses on working through techniques to solve common web issues and the know-hows using NGINX modules. Finally, we will also explore different configurations that will help you troubleshoot NGINX server and assist with performance tuning.

Style and approach

This is a mastering guide where you will follow an instructional, conversational approach working through problems and their solutions.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Mastering NGINX - Second Edition
    1. Table of Contents
    2. Mastering NGINX - Second Edition
    3. Credits
    4. About the Author
    5. About the Reviewer
    6. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why subscribe?
    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. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Installing NGINX and Third-Party Modules
      1. Installing NGINX using a package manager
        1. Installing NGINX on CentOS
        2. Installing NGINX on 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
        3. Configure options for a mail proxy
          1. Table: Mail configure options
        4. Configure options to specify paths
          1. Table – HTTP configuration options
      3. Configuring SSL support
      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. Adding support for Lua
      7. Putting it all together
      8. Summary
    9. 2. A Configuration Guide
      1. The basic configuration format
      2. NGINX global configuration parameters
      3. Using the include files
      4. The HTTP server section
        1. Client directives
        2. File I/O directives
        3. Hash directives
        4. Socket directives
        5. Sample configuration
      5. The virtual server section
      6. Locations – where, when, and how
      7. Full sample configuration
      8. Summary
    10. 3. Using the mail Module
      1. Basic proxy service
        1. The mail server configuration section
        2. POP3 service
        3. IMAP service
        4. SMTP service
        5. Using SSL/TLS
        6. 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. Introducing reverse proxying
      2. The proxy module
      3. Legacy servers with cookies
      4. The upstream module
      5. Keepalive connections
      6. Types of upstream servers
      7. Single upstream server
      8. Multiple upstream servers
      9. Non-HTTP upstream servers
        1. Memcached upstream servers
        2. FastCGI upstream servers
        3. SCGI upstream servers
        4. The uWSGI upstream servers
      10. Load-balancing
        1. Load-balancing algorithms
      11. Converting an if-fy configuration to a more modern interpretation
      12. Using error documents to handle upstream problems
      13. Determining the client's real IP address
      14. 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 data
        2. Caching data
        3. Storing data
        4. Compressing data
      4. Summary
    13. 6. The NGINX HTTP Server
      1. NGINX's architecture
      2. The HTTP core module
        1. The server directive
        2. Logging in NGINX
        3. Finding files
        4. Name resolution
        5. Interacting with the client
      3. Using limits to prevent abuse
      4. Restricting access
      5. Streaming media files
      6. Predefined variables
      7. SPDY and HTTP/2
      8. Using NGINX with PHP-FPM
        1. An example Drupal configuration
      9. Wiring NGINX and uWSGI together
        1. An example Django configuration
      10. Summary
    14. 7. NGINX for the Application Developer
      1. Caching integration
        1. No application caching
        2. Caching in the database
        3. Caching in the filesystem
      2. Changing content on-the-fly
        1. Using the addition module
        2. The sub module
        3. The xslt module
      3. Using Server Side Includes
      4. Decision-making in NGINX
      5. Creating a secure link
      6. Generating images
      7. Tracking website visitors
      8. Preventing inadvertent code execution
      9. Summary
    15. 8. Integrating Lua with NGINX
      1. The ngx_lua module
      2. Integrating with Lua
      3. Logging with Lua
      4. Summary
    16. 9. Troubleshooting Techniques
      1. Analyzing log files
        1. The formats of the error_log file
        2. Error log file entry examples
      2. Configuring advanced logging
        1. Debug logging
        2. Switching binaries at runtime
        3. 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
    17. A. Directive Reference
    18. B. The Rewrite Rule Guide
      1. Introducing the rewrite module
      2. Creating new rewrite rules
      3. Translating from Apache
        1. Rule #1 – Replacing directory and file existence checks with try_files
        2. Rule #2 – Replacing matches against REQUEST_URI with a location
        3. Rule #3 – Replacing matches against HTTP_HOST with a server
        4. Rule #4 – Replacing RewriteCond with if for variable checks
      4. Summary
    19. C. The NGINX Community
      1. NGINX Plus
      2. Mailing list
      3. IRC channel
      4. Web resources
      5. Writing a good bug report
      6. Summary
    20. D. Persisting Solaris Network Tunings
    21. Index