0%

Book Description

Nginx can be an ideal replacement or supplement to Apache. Learn just how straightforward it can be to embrace the Nginx alternative and run a server designed 100% for today’s web using this brilliant tutorial.

  • Complete configuration directive and module reference
  • Discover possible interactions between Nginx and Apache to get the best of both worlds
  • Learn to configure your servers and virtual hosts efficiently
  • Discover possible interactions between Nginx and Apache to get the best of both worlds
  • A step-by-step guide to switching from Apache to Nginx

In Detail

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

"Nginx HTTP Server Second Edition" provides a detailed guide to setting up Nginx in different ways that correspond to actual production situations: as a standalone server, as a 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 beginners, 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 more experienced administrators, this book provides different angles of approach that can help you make the most of your current infrastructure. Nginx can be employed in many situations, whether you are looking to construct an entirely new web-serving architecture or simply want to integrate an efficient tool to optimize your site loading speeds.

This book takes you through the setup and configuration of Nginx by detailing every step of the way, from downloading to configuring your server in a selection of common architectures.

Table of Contents

  1. Nginx HTTP Server - Second Edition
    1. Table of Contents
    2. Nginx HTTP Server - Second Edition
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      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. Downloading and Installing Nginx
      1. Setting up the prerequisites
        1. GCC – GNU Compiler Collection
        2. The PCRE library
        3. The 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. Init script for Debian-based distributions
        4. Init script for Red Hat-based distributions
        5. Installing the script
          1. Debian-based distributions
          2. Red Hat-based distributions
      6. Summary
    9. 2. 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
    10. 3. HTTP Configuration
      1. HTTP Core module
        1. Structure blocks
      2. Module directives
        1. Socket and host configuration
          1. listen
          2. server_name
          3. server_name_in_redirect
          4. server_names_hash_max_size
          5. server_names_hash_bucket_size
          6. port_in_redirect
          7. tcp_nodelay
          8. tcp_nopush
          9. sendfile
          10. sendfile_max_chunk
          11. send_lowat
          12. reset_timedout_connection
        2. Paths and documents
          1. root
          2. alias
          3. error_page
          4. if_modified_since
          5. index
          6. recursive_error_pages
          7. try_files
        3. Client requests
          1. keepalive_requests
          2. keepalive_timeout
          3. keepalive_disable
          4. send_timeout
          5. client_body_in_file_only
          6. client_body_in_single_buffer
          7. client_body_buffer_size
          8. client_body_temp_path
          9. client_body_timeout
          10. client_header_buffer_size
          11. client_header_timeout
          12. client_max_body_size
          13. large_client_header_buffers
          14. lingering_time
          15. lingering_timeout
          16. lingering_close
          17. ignore_invalid_headers
          18. chunked_transfer_encoding
          19. max_ranges
        4. MIME types
          1. types
          2. default_type
          3. types_hash_max_size
        5. Limits and restrictions
          1. limit_except
          2. limit_rate
          3. limit_rate_after
          4. satisfy
          5. internal
        6. File processing and caching
          1. disable_symlinks
          2. directio
          3. directio_alignment
          4. open_file_cache
          5. open_file_cache_errors
          6. open_file_cache_min_uses
          7. open_file_cache_valid
          8. read_ahead
        7. Other directives
          1. log_not_found
          2. log_subrequest
          3. merge_slashes
          4. msie_padding
          5. msie_refresh
          6. resolver
          7. resolver_timeout
          8. server_tokens
          9. underscores_in_headers
          10. variables_hash_max_size
          11. variables_hash_bucket_size
          12. post_action
      3. Module variables
        1. Request headers
        2. Response headers
        3. Nginx generated
      4. The Location block
        1. Location modifier
          1. The = modifier
          2. No modifier
          3. The ~ modifier
          4. The ~* modifier
          5. The ^~ modifier
          6. The @ modifier
        2. Search order and priority
          1. Case 1:
          2. Case 2:
          3. Case 3:
      5. Summary
    11. 4. 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 connections
          4. Limit request
        3. Content and encoding
          1. Empty GIF
          2. FLV and MP4
          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. Split Clients
        6. SSL and security
          1. SSL
          2. Setting up an SSL certificate
          3. Secure link
        7. Other miscellaneous modules
          1. Stub status
          2. Degradation
          3. Google-perftools
          4. WebDAV
        8. Third-party modules
      4. Summary
    12. 5. PHP and Python with Nginx
      1. Introduction to FastCGI
        1. Understanding the CGI mechanism
        2. Common Gateway Interface (CGI)
        3. Fast Common Gateway Interface (FastCGI)
        4. uWSGI and SCGI
        5. Main directives
        6. FastCGI caching
        7. 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. Requirements
          3. Building PHP
          4. Post-install configuration
          5. 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
    13. 6. Apache and Nginx Together
      1. Nginx as reverse proxy
        1. Understanding the issue
        2. The reverse proxy mechanism
        3. Advantages and disadvantages of the mechanism
      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. Improving the reverse proxy architecture
        1. Forwarding the correct IP address
        2. SSL issues and solutions
        3. Server control panel issues
      5. Summary
    14. 7. 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
    15. A. Directive Index
    16. B. Module Reference
      1. Access
      2. Addition*
      3. Auth_basic module
      4. Autoindex
      5. Browser
      6. Charset
      7. Core
      8. DAV*
      9. Degradation*
      10. Empty GIF
      11. Events
      12. FastCGI
      13. FLV*
      14. Geo
      15. Geo IP*
      16. Google-perftools*
      17. Gzip
      18. Gzip Static*
      19. Headers
      20. HTTP Core
      21. Image Filter*
      22. Index
      23. Limit Conn
      24. Limit Requests
      25. Log
      26. Map
      27. Memcached
      28. MP4*
      29. Proxy
      30. Random index*
      31. Real IP*
      32. Referer
      33. Rewrite
      34. SCGI
      35. Secure Link*
      36. Split Clients
      37. SSI
      38. SSL*
      39. Stub status*
      40. Substitution*
      41. Upstream
      42. User ID
      43. uWSGI
      44. XSLT*
    17. C. Troubleshooting
      1. General tips on troubleshooting
        1. Checking access permissions
        2. Testing your configuration
        3. Have you reloaded the service?
        4. Checking logs
      2. Install issues
      3. The 403 Forbidden custom error page
      4. 400 Bad Request
      5. Location block priorities
      6. If block issues
        1. Inefficient statements
          1. Unexpected behavior
    18. Index
18.223.114.142