You are previewing Nginx Troubleshooting.
O'Reilly logo
Nginx Troubleshooting

Book Description

Investigate and solve problems with Nginx-powered websites using a deep understanding of the underlying principles

About This Book

  • Solve problems with your Nginx-powered websites before your audience notices anything

  • Peek into the Nginx architecture and gain knowledge that will help you be valuable to you in the long run

  • Gain knowledge of different types of problems in a step-by-step way

  • Who This Book Is For

    The book is for technical specialists who already use Nginx to serve web pages for their users. Whether you are an experienced system administrator or a new professional, this book will help you do your job in the most efficient way.

    What You Will Learn

  • Detect and investigate problems with your web servers

  • Create correct and professional configuration files

  • Get an in-depth understanding of the web server software

  • Interpret Nginx log files easily and with actionable insights

  • Make your websites respond as fast as possible

  • Prevent problems by setting up proper monitoring and alerts

  • In Detail

    Nginx is clearly winning the race to be the dominant software to power modern websites. It is fast and open source, maintained with passion by a brilliant team. This book will help you maintain your Nginx instances in a healthy and predictable state.

    It will lead you through all the types of problems you might encounter as a web administrator, with a special focus on performance and migration from older software.

    You will learn how to write good configuration files and will get good insights into Nginx logs. It will provide you solutions to problems such as missing or broken functionality and also show you how to tackle performance issues with the Nginx server. A special chapter is devoted to the art of prevention, that is, monitoring and alerting services you may use to detect problems before they manifest themselves on a big scale. The books ends with a reference to error and warning messages Nginx could emit to help you during incident investigations.

    Style and approach

    This comprehensive tutorial on Nginx troubleshooting takes an practical approach to guiding you through common issues in Nginx server.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the code file.

    Table of Contents

    1. Nginx Troubleshooting
      1. Table of Contents
      2. Nginx Troubleshooting
      3. Credits
      4. About the Author
      5. About the Reviewers
        1. eBooks, discount offers, and more
          1. Why subscribe?
      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. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. Searching for Problems in Nginx Configuration
        1. Introducing basic configuration syntax, directives, and testing
          1. Simple directives
          2. Multiline directives
          3. Include directive
        2. Testing Nginx configuration
          1. The default configuration directory layout
          2. A quick example of modifying the MIME types registry
          3. Default nginx.conf
          4. The http directive
        3. Common mistakes in configuration
          1. Semicolons and newlines
          2. File permissions
          3. Variables
          4. Regular expressions
        4. Summary
      9. 2. Searching for Problems in Log Files
        1. Configuring Nginx logging
          1. Logging POST requests
          2. Conditional logging
          3. Logging big request bodies
        2. Creating infrastructure around logs
          1. Configuring log rotation
          2. Working with a lot of log data
          3. Reading logs
            1. Error log record
        3. Summary
      10. 3. Troubleshooting Functionality
        1. Processing a complain
          1. Rolling back
            1. Keeping Nginx configuration under source control
          2. Keeping a case journal
          3. Performing the simplest test
          4. Performing the Internet connection test
          5. Testing the general HTTP response traffic
            1. Detecting a lying application
            2. Working around an integration failure
              1. The try_files directive
              2. Setting up automatic removal from upstream
              3. Configuring the good old SSI
            3. Planning for more complete monitoring
          6. Processing a situation of no traffic
            1. Restarting Nginx properly
          7. Investigating lower than usual traffic
        2. Summary
      11. 4. Optimizing Website Performance
        1. Why Nginx is so fast?
        2. Optimizing individual upstreams
          1. Optimizing static files
          2. Optimizing PHP backends
          3. Java backends
          4. Optimizing Python and Ruby backends
          5. Optimizing Perl backends
        3. Using thread pools in Nginx
        4. The caching layer of Nginx
          1. Emitting caching headers
          2. Caching in Nginx upstream modules
          3. Caching static files
        5. Replacing external redirects with internal ones
        6. Summary
      12. 5. Troubleshooting Rare Specific Problems
        1. Security warnings
          1. Domain name mismatch
          2. Expired certificates
          3. Insecure warnings for valid certificates
          4. The mixed – content warning
            1. Building a secure proxy for the external content
        2. Solving problems with cache
        3. Obsolete pages and VirtualBox
        4. Apache migration problems
        5. Solving problems with WebSockets
        6. Showing a file upload progress bar
        7. Solving the problem of an idle upstream
        8. Summary
      13. 6. Monitoring Nginx
        1. Using ngxtop
        2. Getting statistics from http_stub_status
        3. Monitoring Nginx with Munin
        4. Configuring alerts
        5. Getting more status data from Nginx
        6. Using Nginx Plus alternatives
          1. nginx-module-vts
          2. Luameter
          3. nginx-lua-stats
          4. The upsteam_check module in tengine
          5. The requests/sec patch by Catap
          6. The Ustats module
        7. Summary
      14. 7. Going Forward with Nginx
        1. System administration
          1. Linux/Unix operating system as a whole
          2. Modern Internet protocols
          3. Specific backend software used in your company
          4. Modern cloud platforms
          5. Automation
        2. Software development
        3. Summary
      15. A. Rare Nginx Error Messages
      16. Index