Derek DeJonghe
Compliments of
Complete
NGINX
Cookbook
Derek DeJonghe
Complete NGINX Cookbook
Advanced Recipes for Operations
Boston Farnham Sebastopol TokyoBeijing Boston Farnham Sebastopol TokyoBeijing
978-1-491-96895-6
[LSI]
NGINX Cookbook
by Derek DeJonghe
Copyright © 2017 O’Reilly Media Inc. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA
95472.
O’Reilly books may be purchased for educational, business, or sales promotional use.
Online editions are also available for most titles (http://oreilly.com/safari). For more
information, contact our corporate/institutional sales department: 800-998-9938 or
corporate@oreilly.com.
Editor: Virginia Wilson
Acquisitions Editor: Brian Anderson
Production Editor: Shiny Kalapurakkel
Copyeditor: Amanda Kersey
Proofreader: Sonia Saruba
Interior Designer: David Futato
Cover Designer: Karen Montgomery
Illustrator: Rebecca Demarest
March 2017: First Edition
Revision History for the First Edition
2017-05-26: First Release
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. NGINX Cook‐
book, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the
information and instructions contained in this work are accurate, the publisher and
the author disclaim all responsibility for errors or omissions, including without limi‐
tation responsibility for damages resulting from the use of or reliance on this work.
Use of the information and instructions contained in this work is at your own risk. If
any code samples or other technology this work contains or describes is subject to
open source licenses or the intellectual property rights of others, it is your responsi‐
bility to ensure that your use thereof complies with such licenses and/or rights.
Table of Contents
Part I. Part I: Load Balancing and HTTP Caching
1. High-Performance Load Balancing. . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.0 Introduction
1
1.1 HTTP Load Balancing 2
1.2 TCP Load Balancing 3
1.3 Load-Balancing Methods 4
1.4 Connection Limiting 6
2. Intelligent Session Persistence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.0 Introduction
9
2.1 Sticky Cookie 10
2.2 Sticky Learn 11
2.3 Sticky Routing 12
2.4 Connection Draining 13
3. Application-Aware Health Checks. . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.0 Introduction
15
3.1 What to Check 15
3.2 Slow Start 16
3.3 TCP Health Checks 17
3.4 HTTP Health Checks 18
4. High-Availability Deployment Modes. . . . . . . . . . . . . . . . . . . . . . . . 21
4.0 Introduction 21
4.1 NGINX HA Mode 21
v