You are previewing Nginx HTTP Server.
O'Reilly logo
Nginx HTTP Server

Book Description

"

Adopt Nginx for your web applications to make the most of your infrastructure and serve pages faster than ever

  • Get started with Nginx to serve websites faster and safer

  • Learn to configure your servers and virtual hosts efficiently

  • Set up Nginx to work with PHP and other applications via FastCGI

  • Explore possible interactions between Nginx and Apache to get the best of both worlds

  • A step-by-step guide to switching from Apache to Nginx

  • Complete configuration directive and module reference

In Detail

Nginx is a lightweight HTTP server designed for high-traffic websites, with network scalability as 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 serve as full replacement of other software such as Apache, or stand in front of your existing infrastructure to improve its overall speed. However, migrating to Nginx requires some guidance.

This book serves as a detailed guide to setting up Nginx in different production situations: as standalone server, as reverse proxy, interacting with applications via FastCGI, and more. In addition, the 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 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.

By the end of this book, you will be geared up to implement Nginx as a web server that will boost the speed of all your web applications.

A handy guide to setting up Nginx as a standalone web server or as a reverse proxy, with complete directive and module references

"

Table of Contents

  1. Nginx HTTP Server
    1. Nginx HTTP Server
    2. Credits
    3. About the Author
    4. About the Reviewers
    5. 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. Errata
        2. Piracy
        3. Questions
    6. 1. Preparing your Work Environment
      1. Setting up a terminal emulator
        1. Finding and downloading PuTTY
        2. Creating a session
        3. Working with PuTTY and the shell
      2. Basic shell commands
        1. File and directory management
        2. User and group management
          1. Superuser account
          2. User accounts
          3. Group management
        3. Programs and processes
          1. Starting an application
          2. System services
          3. Process management
            1. Finding the pid
            2. An administrator's best friend top
            3. Killing processes
      3. Discovering the Linux filesystem
        1. Directory structure
        2. Special files and devices
          1. Device types
          2. Pseudo devices
          3. Mounting a storage device
        3. Files and inodes
          1. EXT3 filesystem specifications
          2. Filenames
          3. Inodes
          4. Atime, ctime, and mtime
          5. Symbolic and hard links
        4. File manipulation
          1. Reading a file
          2. Editing a file
          3. Compression and archiving
      4. System administration tools
        1. Running a command as Superuser
          1. Su command
          2. Sudo command
        2. System verification and maintenance
          1. Disk Free
          2. Disk Usage
          3. Free memory
        3. Software packages
          1. Package managers
          2. Downloading and installing packages manually
          3. Building from source
        4. Files and permissions
          1. Understanding file permissions
          2. Directory permissions
          3. Octal representation
          4. Changing permissions
          5. Changing ownership and group
      5. Summary
    7. 2. Downloading and Installing Nginx
      1. Setting up the prerequisites
        1. GCC-GNU Compiler Collection
        2. PCRE library
        3. zlib library
        4. OpenSSL
      2. Downloading Nginx
        1. Websites and resources
        2. Version branches
        3. Features
        4. Downloading and extracting
      3. Configure options
        1. The easy way
        2. Path options
        3. Prerequisites options
        4. Module options
          1. Modules enabled by default
          2. Modules disabled by default
        5. Miscellaneous options
        6. Configuration examples
          1. About the prefix switch
          2. Regular HTTP and HTTPS servers
          3. All modules enabled
          4. Mail server proxy
        7. Build configuration issues
          1. Make sure you installed the prerequisites
          2. Directories exist and are writable
        8. Compiling and installing
      4. Controlling the Nginx service
        1. Daemons and services
        2. User and group
        3. Nginx command-line switches
        4. Starting and stopping the daemon
        5. Testing the configuration
        6. Other switches
      5. Adding Nginx as a system service
        1. System V scripts
        2. What is an init script?
        3. Creating an init script for Nginx
        4. Installing the script
          1. Debian-based distributions
          2. Red Hat-based distributions
      6. Summary
    8. 3. Basic Nginx Configuration
      1. Configuration file syntax
        1. Configuration Directives
        2. Organization and inclusions
        3. Directive blocks
        4. Advanced language rules
          1. Directives accept specific syntaxes
          2. Diminutives in directive values
          3. Variables
          4. String values
      2. Base module directives
        1. What are base modules?
        2. Nginx process architecture
        3. Core module directives
        4. Events module
        5. Configuration module
      3. A configuration for your profile
        1. Understanding the default configuration
        2. Necessary adjustments
        3. Adapting to your hardware
      4. Testing your server
        1. Creating a test server
        2. Performance tests
          1. Httperf
          2. Autobench
          3. OpenWebLoad
        3. Upgrading Nginx gracefully
      5. Summary
    9. 4. HTTP Configuration
      1. HTTP Core module
        1. Structure blocks
      2. Module directives
        1. Socket and host configuration
        2. Paths and documents
        3. Client requests
        4. MIME Types
        5. Limits and restrictions
        6. File processing and caching
        7. Other directives
      3. Module variables
        1. Request headers
        2. Response headers
        3. Nginx generated
      4. The Location block
        1. Location modifier
        2. Search order and priority
          1. Case 1:
          2. Case 2:
          3. Case 3:
      5. Summary
    10. 5. Module Configuration
      1. Rewrite module
        1. Reminder on regular expressions
          1. Purpose
          2. PCRE syntax
          3. Quantifiers
          4. Captures
        2. Internal requests
          1. error_page
          2. Rewrite
          3. Infinite loops
          4. Server Side Includes (SSI)
        3. Conditional structure
        4. Directives
        5. Common rewrite rules
          1. Performing a search
          2. User profile page
          3. Multiple parameters
          4. Wikipedia-like
          5. News website article
          6. Discussion board
      2. SSI module
        1. Module directives and variables
        2. SSI Commands
          1. File includes
          2. Working with variables
          3. Conditional structure
          4. Configuration
      3. Additional modules
        1. Website access and logging
          1. Index
          2. Autoindex
          3. Random index
          4. Log
        2. Limits and restrictions
          1. Auth_basic module
          2. Access
          3. Limit zone
          4. Limit request
        3. Content and encoding
          1. Empty GIF
          2. FLV
          3. HTTP headers
          4. Addition
          5. Substitution
          6. Gzip filter
          7. Gzip static
          8. Charset filter
          9. Memcached
          10. Image filter
          11. XSLT
        4. About your visitors
          1. Browser
          2. Map
          3. Geo
          4. GeoIP
          5. UserID filter
          6. Referer
          7. Real IP
        5. SSL and security
          1. SSL
          2. Setting up an SSL certificate
          3. Secure link
        6. Other miscellaneous modules
          1. Stub status
          2. Google-perftools
          3. WebDAV
        7. Third-party modules
      4. Summary
    11. 6. PHP and Python with Nginx
      1. Introduction to FastCGI
        1. Understanding the mechanism
        2. Common Gateway Interface (CGI)
        3. Fast Common Gateway Interface (FastCGI)
        4. Main directives
        5. FastCGI caching
        6. Upstream blocks
          1. Module syntax
          2. Server directive
      2. PHP with Nginx
        1. Architecture
        2. PHP-FPM
        3. Setting up PHP and PHP-FPM
          1. Downloading and extracting
          2. Patching
          3. Requirements
          4. Building PHP
          5. Post-install configuration
          6. Running and controlling
        4. Nginx configuration
      3. Python and Nginx
        1. Django
        2. Setting up Python and Django
          1. Python
          2. Django
          3. Starting the FastCGI process manager
        3. Nginx configuration
      4. Summary
    12. 7. Apache and Nginx Together
      1. Nginx as reverse proxy
        1. Understanding the issue
        2. The reverse proxy mechanism
        3. Advantages and disadvantages
      2. Nginx Proxy module
        1. Main directives
        2. Caching, buffering, and temporary files
        3. Limits, timeouts, and errors
        4. Other directives
        5. Variables
      3. Configuring Apache and Nginx
        1. Reconfiguring Apache
          1. Configuration overview
          2. Resetting the port number
          3. Accepting local requests only
        2. Configuring Nginx
          1. Enabling proxy options
          2. Separating content
        3. Advanced configuration
      4. Additional steps
        1. Forwarding the correct IP address
        2. SSL issues and solutions
        3. Server control panel issues
      5. Summary
    13. 8. From Apache to Nginx
      1. Nginx versus Apache
        1. Features
          1. Core and functioning
          2. General functionality
        2. Flexibility and community
        3. Performance
        4. Usage
        5. Conclusion
      2. Porting your Apache configuration
        1. Directives
        2. Modules
        3. Virtual hosts and configuration sections
          1. Configuration sections
          2. Creating a virtual host
        4. htaccess files
          1. Reminder on Apache .htaccess files
          2. Nginx equivalence
      3. Rewrite rules
        1. General remarks
          1. On the location
          2. On the syntax
          3. RewriteRule
        2. WordPress
        3. MediaWiki
        4. vBulletin
      4. Summary
    14. A. Directive Index
    15. B. Module Reference
      1. Access
      2. Addition*
      3. Auth_basic module
      4. Autoindex
      5. Browser
      6. Charset
      7. Core
      8. DAV*
      9. Empty GIF
      10. Events
      11. FastCGI
      12. FLV*
      13. Geo
      14. Geo IP*
      15. Google-perftools*
      16. Gzip
      17. Gzip Static*
      18. Headers
      19. HTTP Core
      20. Image Filter*
      21. Index
      22. Limit Requests
      23. Limit Zone
      24. Log
      25. Map
      26. Memcached
      27. Proxy
      28. Random index*
      29. Real IP*
      30. Referer
      31. Rewrite
      32. Secure Link*
      33. SSI
      34. SSL*
      35. Stub status*
      36. Substitution*
      37. Upstream
      38. User ID
      39. XSLT*
    16. C. Troubleshooting
      1. General tips on troubleshooting
        1. Checking access permissions
        2. Testing your configuration
        3. Have you reloaded the service?
        4. Checking logs
        5. Install issues
        6. 403 Forbidden custom error page
        7. Location block priorities
        8. If block issues
          1. Inefficient statements
          2. Unexpected behavior