This short guide explains how to display Nginx statistics when a certain location is requested, usually at /nginx_status. For more information see the HttpStubStatusModule wiki page.
|
1 2 3 4 |
Active connections: 6 server accepts handled requests 1559 1559 7088 Reading: 5 Writing: 1 Waiting: 0 |
Step 1 – Compile Nginx with HttpStupStatusModule
Displaying Nginx’s status requires the HttpStubStatusModule. This module is not included by default during compilation. If you installed Nginx from a package, it may have been included.
Pass the following flag during configuration to include HttpStubStatusModule:
|
1 |
--with-http_stub_status_module |
Step 2 – Add location to site’s configuration file
Add the following to your site’s configuration file, optionally replacing /nginx_status with a custom location.
|
1 2 3 4 |
location /nginx_status { stub_status on; access_log off; } |
- stub_status on indicates this location has a special function. Rather than displaying a file or directory, only statistics for Nginx will be shown.
- access_log off disables logging for this location.
Step 3 – Limit access to the status page
Note that the status page by default will be public. To keep it private, consider:
- Using a custom location that is hard to guess
- Password protecting the page
- Limiting the page to only your IP address