http_stub_status_module是Nginx的一个内置模块,用于提供基本的状态监控信息。以下是添加该模块的方法:
首先检查当前Nginx是否已经包含该模块:
nginx -V 2>&1 | grep -o with-http_stub_status_module
如果有输出则表示已安装。
在编译时添加--with-http_stub_status_module
参数:
./configure --with-http_stub_status_module
make
sudo make install
nginx -V
--with-http_stub_status_module
重新编译:./configure [原有参数] --with-http_stub_status_module
make
make install
,而是替换二进制文件:sudo cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
sudo cp objs/nginx /usr/local/nginx/sbin/nginx
sudo make upgrade
在Nginx配置文件中添加:
server {
listen 80;
server_name localhost;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1; # 只允许本地访问
deny all; # 拒绝其他所有IP
}
}
sudo nginx -s reload
访问http://your-server/nginx_status
,应该能看到类似以下输出:
Active connections: 1
server accepts handled requests
5 5 5
Reading: 0 Writing: 1 Waiting: 0