事情本身不复杂,线索都在日志里。CentOS 7.9 上想通过 nginx 看 FPM 状态,访问 /status 返回 502,FPM 池里已经打开 pm.status_path = /status,php-fpm 进程也在正常处理业务请求。
第一反应是「listen.allowed_clients 没放行,状态请求被 FPM 拒绝」,验证下来不成立。
原因不止一个,得分开看。status 路径没有被 fastcgi_pass 到正确的 socket,请求落到了默认 location。还有一种是location 写的是精确匹配,访问时多带了斜杠导致不命中。
另外,nginx 的 location 顺序里正则先命中,把 /status 当成了 PHP 文件。
先在机器上直接请求 FPM 的状态
cgi-fcgi -bind -connect /run/php-fpm/www.sock 2>/dev/null | head -5
补一个精确匹配的 location
printf 'location = /status {\n fastcgi_pass unix:/run/php-fpm/www.sock;\n include fastcgi_params;\n}\n' > /etc/nginx/conf.d/status.conf
然后确认池里允许本机访问
grep -n 'listen.allowed_clients' /etc/php-fpm.d/www.conf
剩下的就是重载后由内网访问验证
nginx -t && nginx -s reload && curl -s http://127.0.0.1/status?plain | head
报错是间歇性的,我蹲守了半小时才抓到一次完整现场。
恢复的判定其实很直接。访问 /status 返回进程池的文本统计,能看到 active 和 idle 进程数,nginx 错误日志里不再有 connect 失败。
容易忽略的是,状态页不要暴露到公网,最好加 allow 内网段;location 用 = 精确匹配,避免被后面的正则抢走。这类问题最好一次改到位,反复小改反而容易把原因搅混。
