NGINX HTTP Server - Fifth Edition

Book description

Master NGINX to elevate, accelerate, and optimize your cloud infrastructure

Key Features

  • Discover the potential of running NGINX in your environment
  • Run NGINX in harmony with your existing cloud infrastructure
  • Learn how to fine-tune and adjust NGINX's configuration for best performance
  • Purchase of the print or Kindle book includes a free PDF eBook

Book Description

Explore the capabilities of NGINX, a robust HTTP server designed for handling high-traffic websites, with network scalability as its primary objective. Whether you’re a beginner or an experienced administrator, this NGINX book will guide you through the complete process of setting up this lightweight HTTP server, from quick and basic configurations to more detailed configurations tailored to your needs. Highlighting the latest version 1.25.2, featuring new features such as HTTP/3 and QUIC, this edition keeps you up to date with cutting-edge developments.

This book is packed with a multitude of real-world examples, which will help you secure your infrastructure with automatic TLS certificates, expertly place NGINX in front of your existing applications, and do much more. From orchestration and Docker to bandwidth management, OpenResty, and NGINX Plus commercial features, you’ll get to grips with enhancing and optimizing your infrastructure or designing brand-new architecture. Moreover, this updated edition will show you how NGINX excels in cloud environments with guides on integrating NGINX with cloud services for deploying scalable architectures efficiently and securely.

By the end of this book, you’ll be able to adapt and use a wide variety of NGINX implementations to tackle diverse challenges with confidence.

What you will learn

  • Install and configure a basic setup for NGINX and test it out
  • Discover the core functionality of the HTTP module as well as third-party modules
  • Understand how to set up NGINX to work with PHP, Python, and other applications
  • Optimize your architecture with threads or load balancing
  • Configure NGINX with orchestration and work in a Docker environment
  • Identify errors in configuration and grasp basic troubleshooting techniques

Who this book is for

This book is for beginners and web administrators looking to master the powerful and secure NGINX HTTP server. Whether you want to replace your existing web server software or integrate a new tool to collaborate with applications that are already up and running, this book will help you achieve your goals. To get started, all you need is access to a Linux server and a basic understanding of web server concepts.

Table of contents

  1. NGINX HTTP Server
  2. Contributors
  3. About the authors
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Conventions used
    6. Get in touch
    7. Share Your Thoughts
    8. Download a free PDF copy of this book
  6. Part 1:Begin with NGINX
  7. Chapter 1: Downloading and Installing NGINX
    1. Installing NGINX via package managers
      1. NGINX-provided packages
    2. Compiling NGINX from source
      1. Installing GNU Compiler Collection
      2. The PCRE library
      3. The zlib library
      4. OpenSSL
    3. Downloading and compiling the NGINX source code
      1. Websites and resources
      2. Version branches
      3. Features
      4. Downloading and extracting
    4. Exploring the options for configuring the compilation
      1. The easy way
      2. Path options
      3. Build configuration issues
      4. Compiling and installing
    5. Controlling the NGINX service
      1. Daemons and services
      2. Users and groups
      3. NGINX command-line switches
      4. Starting and stopping the daemon
      5. Testing the configuration
      6. Other switches
    6. Adding NGINX as a system service
      1. systemd unit file
      2. Handling system errors
    7. A quick overview of the possibilities offered by NGINX Plus
    8. Summary
  8. Chapter 2: Basic NGINX Configuration
    1. Delving into the configuration file syntax
      1. Configuration directives
      2. Organization and inclusions
      3. Directive blocks
      4. Advanced language rules
    2. Looking at the base module directives
      1. What are base modules?
      2. NGINX process architecture
      3. Core module directives
      4. The events module
      5. Configuration module
      6. Necessary adjustments
    3. Testing your server
      1. Creating a test server
      2. Upgrading NGINX gracefully
    4. Summary
  9. Part 2: Dive into NGINX
  10. Chapter 3: Exploring the HTTP Configuration
    1. An introduction to the HTTP core module and its three new blocks
    2. Exploring the HTTP core 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. Exploring the directives of HTTP/2
      1. http2_chunk_size
      2. http2_body_preread_size
      3. http2_idle_timeout
      4. http2_max_concurrent_streams
      5. http2_max_field_size
      6. http2_max_header_size
      7. http2_max_requests
      8. http2_recv_buffer_size
      9. http2_recv_timeout
      10. Module variables
    4. Exploring the variables introduced by the HTTP core module
      1. Request headers
      2. Response headers
      3. NGINX-generated headers
    5. Understanding and exploring the location block
      1. Location modifier
      2. Search order and priority
    6. Summary
  11. Chapter 4: Exploring Module Configuration in NGINX
    1. Exploring the Rewrite module
      1. Reminder of regular expressions
      2. Internal requests
      3. Conditional structure
      4. Directives
      5. Common rewrite rules
    2. Looking at some additional modules
      1. Website access and logging
      2. Limits and restrictions
      3. Content and encoding
      4. About your visitors
      5. SSL and security
      6. Other miscellaneous and optional modules
    3. Summary
  12. Chapter 5: PHP and Python with NGINX
    1. Introduction to FastCGI technologies
      1. Understanding the CGI mechanism
      2. CGI
      3. FastCGI
      4. uWSGI and SCGI
      5. Main directives
      6. FastCGI caching and buffering
    2. PHP with NGINX
      1. Architecture
      2. PHP-FPM
      3. Setting up PHP and PHP-FPM
      4. NGINX configuration
    3. Python and NGINX
      1. Django
      2. Setting up Python and Django
      3. NGINX configuration
    4. Summary
  13. Chapter 6: NGINX as a Reverse Proxy
    1. Exploring the reverse proxy mechanism
    2. Exploring the NGINX proxy module
      1. Main directives
      2. Caching, buffering, and temporary files
      3. Limits, timeouts, and errors
      4. Other directives
      5. Variables
    3. Looking at NGINX and microservices
    4. Summary
  14. Part 3: NGINX in Action
  15. Chapter 7: Introduction to Load Balancing and Optimization
    1. Introducing load balancing
      1. Understanding the concept of load balancing
      2. Session affinity
      3. The upstream module
      4. Request distribution mechanisms
    2. Using NGINX as a TCP/UDP load balancer
      1. The stream module
      2. An example of MySQL load balancing
    3. Exploring thread pools and I/O mechanisms
      1. Relieving worker processes
      2. AIO, Sendfile, and DirectIO
    4. Summary
  16. Chapter 8: NGINX within a Cloud Infrastructure
    1. Understanding cloud infrastructure
      1. The traditional approach
      2. The cloud approach
    2. Using Docker
      1. Installing Docker
      2. Your first Docker container
      3. Simplifying with Docker Compose
    3. Setting up NGINX inside Docker
      1. Integrating PHP with NGINX using Docker Compose
    4. Setting up NGINX inside Docker to proxy host applications
    5. Summary
  17. Chapter 9: Fully Deploy, Manage, and Auto-Update NGINX with Ansible
    1. Understanding configuration management
    2. Running your first Ansible playbook
    3. Setting up NGINX using Ansible
    4. Setting up automatic updates using Ansible
    5. Summary
  18. Chapter 10: Case Studies
    1. Exploring SSL Certificates and HTTPS by default
      1. Certificate Management with acme.sh
      2. acme.sh and the DNS API
      3. Issuing a signed certificate
      4. Centralizing SSL Configuration with NGINX
      5. Implementing HTTP/2 with SSL
    2. Deploying a WordPress site
      1. Preparing your server and obtaining WordPress
      2. NGINX configuration
      3. WordPress configuration
    3. Deploying Nextcloud
      1. Getting Nextcloud
    4. Summary
  19. Chapter 11: Troubleshooting
    1. Looking at some general tips on NGINX troubleshooting
      1. Checking access permissions
      2. Testing your configuration
      3. Have you reloaded the service?
      4. Checking logs
    2. Installing a log parser
    3. Troubleshooting install issues
    4. Looking at the 403 forbidden custom error page
    5. Exploring 400 Bad Request
    6. Looking at truncated or invalid FastCGI responses
    7. Exploring location block priorities
    8. Looking at if block issues
      1. Inefficient statements
      2. Unexpected behavior
    9. Summary
  20. Index
    1. Why subscribe?
  21. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: NGINX HTTP Server - Fifth Edition
  • Author(s): Gabriel Ouiran, Clement Nedelcu, Martin Bjerretoft Fjordvald
  • Release date: May 2024
  • Publisher(s): Packt Publishing
  • ISBN: 9781835469873