phpenv 默认不启用 http_stub_status_module,需先用 phpenv nginx -v | grep with-http_stub_status_module 确认模块存在;若无输出,则无法在线启用,须换用自编译nginx或其它环境;确认后在 server 块内配置 location /nginx_status { stub_status; allow 127.0.0.1; deny all; } 并重载。

phpEnv 默认不启用 http_stub_status_module,直接配 stub_status 会报 unknown directive "stub_status" 错误。必须先确认模块存在,再配置访问路径和权限控制。
检查 phpEnv 内置 Nginx 是否含 stub_status 模块
phpEnv 封装的 Nginx 通常基于预编译二进制,不一定开启该模块。不能只靠 nginx -v,得用大写 -V 并 grep:
phpenv nginx -V 2>&1 | grep -o with-http_stub_status_module
如果无输出,说明模块未编译进当前 Nginx —— phpEnv 不提供在线启用模块的功能,此时只能:
- 放弃使用 phpEnv 自带 Nginx,改用自己源码编译的 Nginx(启用
--with-http_stub_status_module)并指向同一 PHP 环境 - 或切换到 WAMP/XAMPP/MAMP 等允许自定义编译参数的环境
- 部分新版 phpEnv(如 5.0+)可能通过
phpenv nginx:rebuild --with-http_stub_status_module支持重编译,但需确认其底层是否封装了 configure 调用
在 phpEnv 的 nginx.conf 中添加 status location
确认模块存在后,编辑 phpEnv 管理的 Nginx 配置文件(路径类似 ~/.phpenv/versions/{ver}/etc/nginx/nginx.conf 或通过 phpenv nginx:open 打开),在任一 server 块内插入:
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
注意几点:
-
stub_status是指令,不是函数,不加括号;on可省略(即写stub_status;也生效) - 不要放在
http块顶层,必须嵌套在server或location内,否则报错 -
allow/deny顺序不可颠倒:先allow再deny all,否则全部拒绝 - 若 phpEnv 启用了多端口(如 8080、8000),确保该
server块监听了你实际访问的端口
重载失败常见原因与绕过方案
执行 phpenv nginx:restart 或 phpenv nginx:reload 后仍无法访问,优先排查:
-
nginx -t报 “unknown directive” → 模块确实未编译,非配置问题 - 返回 404 → 请求路径(如
/status)和配置中location路径不一致 - 返回 403 →
allowIP 不匹配,比如你在宿主机 curl,但 phpEnv 运行在 Docker 中,真实来源是容器网关 IP(如172.17.0.1),不是127.0.0.1 - 返回 500 或空白 → 与其他模块冲突(如某些 phpEnv 插件注入了非法 header),可临时注释其他
location块测试
若仅需快速验证状态数据,且 phpEnv 允许修改启动命令,可尝试用 curl -s http://127.0.0.1:8080/nginx_status 替代浏览器访问,避开前端代理或 HTTPS 重定向干扰。
真正卡住的地方往往不是配置语法,而是 phpEnv 封装层对 Nginx 二进制的“黑盒”控制 —— 它不暴露 configure 过程,也不提供模块开关界面。一旦 nginx -V 不显示 with-http_stub_status_module,就只能换环境或自己编译,没有中间路径。
php免费学习视频:立即使用
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!











