Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
NGINX Cookbook

You're reading from   NGINX Cookbook Over 70 recipes for real-world configuration, deployment, and performance

Arrow left icon
Product type Paperback
Published in Aug 2017
Publisher Packt
ISBN-13 9781786466174
Length 278 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Tim Butler Tim Butler
Author Profile Icon Tim Butler
Tim Butler
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Let's Get Started 2. Common PHP Scenarios FREE CHAPTER 3. Common Frameworks 4. All About SSLs 5. Logging 6. Rewrites 7. Reverse Proxy 8. Load Balancing 9. Advanced Features 10. Docker Containers 11. Performance Tuning 12. OpenResty 13. NGINX Plus – The Commercial Offering

Basic monitoring

Monitoring both the performance and uptime of a web server is paramount when you want to ensure consistent performance. There are a number of ways both these aspects can be monitored, all with varying levels of complexity and information. We'll focus on some of the simpler examples to give you a starting point to go forward with.

How to do it...

We can enable the basic NGINX stub_status page to give some rudimentary statistics and service status. To enable, edit your site config and add the following:

location = /nginx_status { 
    stub_status on; 
    access_log   off; 
    allow <YOURIPADDRESS>; 
    deny all; 
} 

To prevent information leakage about your system, we have added the allow command. This should be your IP address. This is followed by the deny all command to prevent anyone else from loading the URL. We've also turned off access logs for this URL to save space.

After reloading your configuration (hint: systemctl reload nginx for systemd-based OS), you can now load the new URL /nginx_status in your browser.

You should see something like the following:

How it works...

Let's take apart the details line-by-line:

  • The Active connections line lists the amount of connections to the server. For a quiet server, this could be less than a dozen. For a busy server, expect this to be in the hundreds.
  • The server accepts handled requests line is little confusing, since it's represented by three numbers (81, 81, and 177 in this example). The first number represents the amount of accepted connections. The second number represents the total number of handled connections. Unless there's a resource limitation, the number of accepted and handled connections should be the same. Next, we have the total number of client requests.
  • The last line represents the state of the active connections. Reading means NGINX is reading the request headers, Writing means NGINX is writing data back to the client, and Waiting means that the client is now idle but still has the connection open (due to keep-alives).
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime