nginx有一个模块叫--with-http_stub_status_module,编译安装nginx时安装它之后,你就能够看到nginx的状态监控页面。
如果你是yum方式安装的nginx较新版本,可能也会自带stub_status module。
编译安装nginx如: ./configure --with-http_stub_status_module
假定你已经编译安装完了nginx(没安装的话参考这个帖子《centos7上编译安装nginx》)
然后去你的站点配置文件中的server{}区域中添加一段下面代码即可。
大家一般都会把nginx编译安装到/usr/local/nginx下。那么配置文件就是/usr/local/nginx/conf/nginx.conf
location /nginx_status {
stub_status on;
access_log off;
allow 192.168.0.0/24;
deny all;
}
nginx_status 是以后我们访问状态页面的路径,比如http://www.hiibm.com/nginx_status,这个路径字符串在配置文件中随你怎么写,到时候URL跟着写和你自定义的一样就行。
stub_status on;是开启相应的模块
allow 192.168.0.0/24;是允许哪些主机能够访问nginx状态监控页面
测试效果。