NGINX is one of the most widely used web servers available today, in part because of itscapabilities as a load balancer and reverse proxy server for HTTP and other network protocols. This revised cookbook provides easy-to-follow examples of real-world problems in application delivery. Practical recipes help you set up and use either the open source or commercial offering to solve problems in various use cases.
For professionals who understand modern web architectures, such as n-tier or microservice designs and common web protocols such as TCP and HTTP, these recipes provide proven solutions for security and software load balancing and for monitoring and maintaining NGINX's application delivery platform. You'll also explore advanced features of both NGINX and NGINX Plus, the free and licensed versions of this server.
You'll find recipes for:
• High-performance load balancing with HTTP, TCP, and UDP
• Securing access through encrypted traffic, secure links, HTTP authentication subrequests, and more
• Deploying NGINX to Google, AWS, and Azure cloud
• Setting up and configuring NGINX Controller
• Installing and configuring the NGINX App Protect module
• Enabling WAF through Controller ADC
• NGINX Instance Manager, Service Mesh, and the njs module
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
# NGINX Cookbook: Advanced Recipes for High-Performance Load Balancing (3rd Edition)
## 【One-Line Pitch】
A practical recipe collection for mastering NGINX and NGINX Plus as load balancers, reverse proxies, and application delivery platforms—essential reading for DevOps engineers, site reliability engineers, and architects managing modern web infrastructures.
## 【Book Arc】
- **Opening (~0%–9%)**: Introduces NGINX's role in modern web architectures, covers installation for both open source and NGINX Plus, and establishes foundational concepts including configuration file structure, process management signals (stop, quit, reload, reopen), and the use of include directives for modular configuration organization.
- **Early (~9%–25%)**: Dives deep into high-performance load balancing across HTTP, TCP, and UDP protocols, explaining horizontal scaling principles, session persistence strategies, and the importance of stateful application handling through cookie tracking and routing mechanisms.
- **Early (~25%–34%)**: Explores advanced load-balancing algorithms including least_time, generic hash, random selection, and IP hash methods, plus NGINX Plus-specific features like connection draining for graceful server maintenance and active health checks.
- **Middle (~34%–44%)**: Covers traffic management techniques including split_clients for A/B testing and canary releases, GeoIP-based country access restrictions, connection limiting with 429 status codes, and bandwidth rate limiting with configurable thresholds.
- **Middle (~44%–47%)**: Focuses on massively scalable content caching, including cache locking to prevent thundering herds, stale cache serving during upstream failures, and strategies for handling static file caching with filename hashing for CDN integration.
- **Late (~47%–100%)**: Progresses to advanced topics including authentication (SAML, JWT), security controls with NGINX App Protect WAF, HTTP/2 and HTTP/3 (QUIC) protocols, gRPC support, media streaming (MP4, HLS, HDS), cloud deployments across AWS/Azure/GCP, and operational concerns like monitoring and performance tuning.
## 【Key Takeaways】
- **Modular configuration is foundational** (Early): Using include directives to split configurations into logical groups prevents unwieldy config files and enables better maintainability across complex deployments.
- **Session persistence requires intelligent load balancing** (Early): When application state is stored locally rather than in shared memory, NGINX must track sessions via cookies or routing to ensure subsequent requests reach the same server—critical for stateful applications at scale.
- **Multiple load-balancing algorithms serve different needs** (Early): From least_time for latency-sensitive workloads to IP hash for session affinity and consistent hashing to minimize redistribution when servers change, choosing the right algorithm directly impacts user experience and infrastructure efficiency.
- **Connection draining enables zero-downtime maintenance** (Early): NGINX Plus's drain parameter allows graceful server removal by stopping new sessions while letting existing ones expire naturally—essential for stateful applications requiring maintenance.
- **Traffic splitting enables safe deployments** (Middle): The split_clients module facilitates A/B testing, canary releases, and blue-green deployments by routing percentages of traffic to different upstream pools, limiting blast radius during rollouts.
- **Rate limiting protects infrastructure** (Middle): Combining connection limits (with 429 status codes) and bandwidth limits (with limit_rate_after thresholds) allows fine-grained control over resource consumption and protects against abuse.
- **Cache locking prevents cache stampedes** (Middle): The proxy_cache_lock directive ensures only one request populates a cache entry while others wait, with age and timeout parameters providing safeguards against slow upstream responses.
- **Stale cache serving ensures availability** (Middle): Configuring proxy_cache_use_stale allows NGINX to serve expired content when upstream servers are unavailable, maintaining user-facing availability during outages.
## 【Reading Tips】
- **Skim Chapter 1 if you're experienced**: The basics of installation and configuration structure are well-covered but may be review for seasoned NGINX users—focus instead on the load-balancing algorithms in Chapter 2.
- **Deep-read the load-balancing chapters**: Chapter 2 is the heart of the book; pay special attention to the algorithm selection guidance and session persistence techniques, as these decisions have long-term architectural implications.
- **Use the recipes as reference patterns**: Rather than reading cover-to-cover, treat this as a cookbook—identify your current problem, find the matching recipe, and adapt the solution to your context.
- **Note the NGINX vs. NGINX Plus distinction**: Many advanced features (active health checks, connection draining, SAML authentication) require the commercial version; check which recipes apply to your license before implementation.
- **Skip ahead for cloud and security chapters if needed**: The later chapters on cloud deployments and WAF configuration are valuable but can be consulted on-demand rather than read sequentially.
## 【Coverage Limits】
This guide synthesizes content from the opening through the middle sections (~47% of the book), covering basics, load balancing, traffic management, and caching. The later chapters on authentication, security controls, HTTP/2/3, media streaming, cloud deployments, and operational topics are listed in the table of contents but not covered in detail in this guide.
##
small as a set of two system copies for high availability, or as large as thousands around the globe, there’s a need for a load-balancing solution that is as...
ns to continue being served for the length of their session. You can also toggle this 20 | Chapter 2: High-Performance Load Balancing listen 1234; proxy_...
irective to ensure only one request is able to write to the cache at a time, where subsequent requests will wait for the response to be written to the cache ...
ip \ -O nginx-saml-main.zip $ unzip nginx-saml-main.zip $ mv nginx-saml-main/* /etc/nginx/conf.d/ The NGINX Plus SAML solution does not yet parse standar...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Loading comments...
Reply to Comment
Edit Comment