Mastering Nginx

(Ron) #1

Troubleshooting Techniques


[ 214 ]

Calling this URI from the localhost (for example, with curl http://localhost/


nginx_status) will show output similar to the following lines:


Active connections: 2532
server accepts handled requests


1476737983 1476737983 3553635810
Reading: 93 Writing: 13 Waiting: 2426


Here we see that there are 2,532 open connections, of which NGINX is currently


reading the request header of 93, and 13 connections are in a state in which NGINX
is either reading the request body, processing the request, or writing a response


to the client. The remaining 2,426 requests are considered keepalive connections.
Since this nginx process was started, it has both accepted and handled 1,476,737,983


connections, meaning that none were closed immediately after having been accepted.


There were a total of 3,553,635,810 requests handled through these 1,476,737,983
connections, meaning there were approximately 2.4 requests per connection.


This kind of data can be collected and graphed using your favorite system metrics


tool chain. There are plugins for Munin, Nagios, collectd, and others, which use the


stub_status module to collect statistics. Over time, you may notice certain trends
and be able to correlate them to specific factors, but only if the data is collected.


Spikes in user traffic as well as changes in the operating system should be visible
in these graphs.


Summary


Problems surface on a number of levels when bringing a new piece of software into


production. Some errors can be tested for and eradicated in a test environment;
others surface only under real load with real users. To discover the reasons for


these problems, NGINX provides very detailed logging, at a number of levels.
Some of the messages may have multiple interpretations, but the overall pattern is


understandable. By experimenting with the configuration and seeing what kinds of


error messages are produced, we can gain a feeling for how to interpret the entries
in the error log. The operating system has an influence on how NGINX runs, as it


imposes certain limits due to default settings for a multiuser system. Understanding
what is going on at the TCP level will help when tuning these parameters to meet


the load under real conditions. Rounding off our tour of troubleshooting, we saw


what kind of information the stub_status module was capable of delivering.
This data can be useful to get an overall idea for how our NGINX is performing.


The appendices are up next. The first is a directive reference, listing all of NGINX's


configuration directives in one place, including default values and in which context


they may be used.

Free download pdf