Steps:
1 compile nginx, add the parameter -- with-http_stub_status_module
Take my own compilation options as an example:
# Configuration instructions. /configure -- prefix =/usr/local -- user = nginx -- group = nginx -- with-http_ssl_module -- with-http_realip_module -- http-client-body-temp-Path =/usr/local/var/tmp /nginx/client -- http-proxy-temp-Path =/usr/local/var/tmp/nginx/Proxy -- http-FastCGI-temp-Path =/usr/local/var /tmp/nginx/fcgi -- http-scgi-temp-Path =/usr/local/var/tmp/nginx/scgi -- http-uwsgi-temp-Path =/usr/local /var/tmp/nginx/uwsgi -- with-http_geoip_module -- with-http_stub_status_module
2. Modify the nginx configuration file and add monitoring Status Configuration
Add the following code to the server block of nginx. conf:
location /nginx_status { # Turn on nginx stats stub_status on; # I do not need logs for stats access_log off; # Security: Only allow access from 192.168.1.100 IP # #allow 192.168.1.100; # Send rest of the world to /dev/null # #deny all;}
This code is added to the default server,
Assume that the default server configuration is
listen 127.0.0.1:80;server_name 127.0.0.1;
Then, you can access nginx through curl 127.0.0.1/nginx_status.
The returned results are similar:
Active connections: 1 server accepts handled requests 655 655 1985 Reading: 0 Writing: 1 Waiting: 0