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
, and177
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, andWaiting
means that the client is now idle but still has the connection open (due to keep-alives).