PHP-FPM 状态页面 - 请求 URI 始终为 /index.php

PHP-FPM 状态页面 - 请求 URI 始终为 /index.php

我正在使用 nginxPHP-FPM

我的应用程序需要将所有 URL 重定向到index.php(请参阅 nginx conf)

location / {
    root /var/www/app/public/
    try_files $uri /index.php?$args;
}


location ~ \.php$ {         
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    try_files $fastcgi_script_name =404;

    set $path_info $fastcgi_path_info;
    fastcgi_param PATH_INFO $path_info;

    fastcgi_index index.php;

    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}

为了分析一些性能问题,我想使用 fpm 状态页面。但状态页面没有显示真正的请求 URI

pid:                  1369
state:                Idle
start time:           03/Sep/2018:17:34:34 +0200
start since:          15
requests:             4
request duration:     29796
request method:       GET
request URI:          /index.php
content length:       0
user:                 -
script:               /var/www/app/public/index.php
last request cpu:     67.12
last request memory:  6291456

因此很难判断当前正在处理哪个页面 - 是否可以向 fpm-status 页面添加一些附加信息或更改请求 URI?

答案1

这对我有用:

 location ~ ^/index\.php(/|$) {
     fastcgi_pass 127.0.0.1:9000;
     fastcgi_split_path_info ^(.+\.php)(/.*)$;
     include fastcgi_params;
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     fastcgi_param SERVER_NAME $http_host;
     fastcgi_param SCRIPT_NAME $request_uri;
 }

参考:https://jolicode.com/blog/how-to-see-full-request-uri-in-fpm-status

答案2

仍然没有答案,五年前就出现了一个错误https://bugs.php.net/bug.php?id=72319没有答复。

答案3

您必须添加一个块及其自己的块和一fastcgi_index组块:

location ~ ^/_status$ {     
    include fastcgi_params
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index index.php;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

    # the following is optional but nice to have
    # it will restrict access to the local monitoring system
    access_log off;
    allow 127.0.0.1;
    allow ::1;
    deny all;

}

答案4

对于我的问题,解决方案是:

        fastcgi_param  PATH_INFO  $request_uri;

相关内容