要让 nginx 支持 /stub_status 状态页,必须在 ./configure 时添加 --with-http_stub_status_module 参数编译进二进制;运行 nginx -v 检查是否已内置该模块,若无则需重新编译并安装,最后在 server 块中配置 location /stub_status 启用。

要让 Nginx 源码编译时支持 /stub_status 状态页,关键是在 ./configure 阶段显式加入 --with-http_stub_status_module 参数。这个模块不支持运行时加载,必须编译进二进制文件。
确认当前是否已启用该模块
执行以下命令检查:
nginx -V 2>&1 | grep -o with-http_stub_status_module
如果有输出,说明已内置,无需重新编译;若无输出,则必须走源码编译流程。
编译前准备依赖和参数
确保系统已安装基础编译工具和 OpenSSL 开发包(HTTPS 场景下还需 --with-http_ssl_module):
- CentOS/RHEL:安装
gcc pcre-devel zlib-devel openssl-devel - Ubuntu/Debian:安装
build-essential libpcre3-dev zlib1g-dev libssl-dev
进入 Nginx 源码目录后,运行 ./configure,至少包含:
--with-http_stub_status_module
推荐同时启用常用模块,例如:
--with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module
完成编译与安装
依次执行:
make && sudo make install
默认安装路径为 /usr/local/nginx,如需自定义,加 --prefix=/your/path。
安装完成后验证:
/usr/local/nginx/sbin/nginx -V 2>&1 | grep stub_status
确认输出中含 with-http_stub_status_module 即表示成功。
配置 location 启用状态页
编辑 nginx.conf,在某个 server 块内添加:
location /stub_status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow 192.168.0.0/16;
deny all;
}
注意:stub_status on 只能在 location 或 server 上下文中使用,不能放在 http 或 upstream 块里。
测试并重载:
nginx -t && nginx -s reload
然后用 curl http://127.0.0.1/stub_status 查看返回结果。











