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

仍然沒有答案,一個錯誤在 5 年前就被打開了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;

相關內容