如何让PHP-FPM状态页显示Laravel的真实请求URI而非/index.php
让PHP-FPM 7.4状态页显示真实请求URI的配置方法
出现所有进程请求URI都显示/index.php的问题,是因为Laravel这类单入口框架的Nginx配置会把所有请求转发到index.php,如果FastCGI参数传递不正确,PHP-FPM就无法获取到原始请求URI。按照以下步骤调整配置即可解决:
1. 修正Nginx的FastCGI参数配置
找到处理PHP请求的location块(通常是location ~ \.php$),确保配置中正确传递原始请求URI参数:
location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.4-fpm.sock; # 根据你的PHP-FPM监听方式调整 # 关键:传递真实请求URI fastcgi_param REQUEST_URI $request_uri; fastcgi_param SCRIPT_NAME $fastcgi_script_name; }
如果是Laravel等框架的根路径location,保持原有的try_files配置即可:
location / { try_files $uri $uri/ /index.php?$query_string; }
2. 确保PHP-FPM状态页配置正确
打开PHP-FPM的pool配置文件(路径通常是/etc/php/7.4/fpm/pool.d/www.conf),确认pm.status_path已配置(比如设置为/fpm-status):
pm.status_path = /fpm-status
同时,需要在Nginx中配置一个location来允许访问状态页:
location /fpm-status { fastcgi_pass unix:/run/php/php7.4-fpm.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; }
3. 重启服务生效
修改配置后,重启Nginx和PHP-FPM服务:
sudo systemctl restart nginx sudo systemctl restart php7.4-fpm
完成以上配置后,再次访问PHP-FPM状态页,就能看到进程对应的真实请求URI(如/user/getDetails)了。
内容的提问来源于stack exchange,提问作者Q8root
相关产品推荐
相关产品推荐

