Statement on glibc/iconv Vulnerability

FPM の情報ページ

このページは、FPM の情報ページをセットアップする方法の説明と、 表示される内容について記しています。 fpm_get_status() も参照ください。

設定

FPM の情報ページは、 FPM プールの設定にある pm.status_path パラメータを設定することで有効にできます。

警告

セキュリティを考慮して、 FPM の情報ページへのアクセスは、 内部的なリクエスト または既知のクライアントIPからのリクエストに限定すべきです。 なぜなら、この情報ページはリクエストURLや、 利用可能なリソースに関する情報を晒してしまっているからです。

ウェブサーバーの設定によっては、 PHP スクリプトをバイパスさせ、 このパスへの直接アクセスを許可する必要があるかもしれません。 Unix Domain Socket(UDS) 経由で listen している FPM と Apache を設定する例は、下記のようになります。 ここでは、 pm.status_path/fpm-status を設定しています:

<LocationMatch "/fpm-status">
 Order Allow,Deny
 Allow from 127.0.0.1
 ProxyPass "unix:/var/run/php-fpm.sock|fcgi://localhost/fpm-status"
</LocationMatch>

FPM とウェブサーバーをリロードまたは再起動した後、 情報ページがブラウザからアクセスできるようになっているはずです。 (IP アドレス制限が設定されている場合は、 リクエストが許可したIPアドレスから来ている場合に限ります)

クエリパラメータ

情報ページの出力フォーマットは、以下のクエリパラメータのうちひとつを指定することで変更できます:

  • html
  • json
  • openmetrics
  • xml

クエリパラメータ full を使うことで、 追加の情報を出力させることもできます。

情報ページのURLの例は、下記のとおりです:

  • https://localhost/fpm-status - デフォルトのテキストフォーマットで、概要を出力します。
  • https://localhost/fpm-status?full - デフォルトのテキストフォーマットで、全ての情報を出力します。
  • https://localhost/fpm-status?json - JSON で 概要を出力します。
  • https://localhost/fpm-status?html&full - HTML フォーマットで、全ての情報を出力します。

表示される情報

日付/時刻 の値は、JSON と XML 出力では Unixタイムスタンプを使います。 それ以外の場合は、 "03/Jun/2021:07:21:46 +0100" のようなフォーマットを使います。

基本情報 - 常に表示されます
パラメータ 説明
pool FPM プロセスプールの名前
proccess manager プロセスマネージャーのタイプ - static, dynamic, または ondemand.
start time プロセスプールが最後に起動した日付/時刻
start since プロセスプールが最後に起動してから経過した秒数
accepted conn 受け入れた接続の合計数
listen queue 空きのプロセスを待っている(backlogに入っている)現在のリクエスト数
max listen queue ある一時点でlisten キューに入ったリクエストの最大数
listen queue len 許可されているlisten キューの最大サイズ
idle processes (リクエストを待っている)現在アイドルなプロセス数
active processes 現在リクエストを処理しているプロセス数
total processes 現在のプロセスの合計数
max active processes 同時にアクティブになったプロセスの最大数
max children reached プロセスの最大数に達したことがあるかを示します。 ある場合、表示は 1 になります。 ない場合、表示は 0 になります。
slow requests 設定した request_slowlog_timeout に到達したリクエストの合計
プロセス単位の情報 - 出力モードが full の場合にだけ表示されます
パラメータ 説明
pid プロセスの PID
state プロセスの状態 - Idle, Running, ...
start time プロセスが起動した日付/時刻
start since プロセスが起動後、経過した秒数
requests 処理したリクエスト数
request duration 直近のリクエストを処理するのに使った時間の合計(ミリ秒単位)
request method 直近のリクエストの HTTP メソッド
request uri 最後に処理したリクエストのURL(webサーバーが処理した後のもの。フロントコントローラーパターンを使っている場合、常に /index.php になる場合があります)
content length 直近のリクエストの、body の長さ(バイト単位)
user 直近のリクエストの HTTP ユーザー (PHP_AUTH_USER)
script 直近のリクエストで実行されたスクリプトのフルパス。 適用できない場合(例: FPM 情報ページへのリクエスト)は、 '-' になります。
last request cpu 直近のリクエストの、%cpu の値。 プロセスがアイドルでない場合、この値は0になります。 なぜなら、リクエストの処理が終わった時にこの値は計算されるからです。 この値は100%を超えることがあります。 なぜならこのメトリクスは、 直近のリクエストで使われたCPU時間の合計をパーセント単位で示すからです - つまりこの値はすべてのコアのプロセスを考慮しますが、 コアがひとつの場合は、100% になります。
last request memory 直近のリクエストが消費したメモリの最大値。 プロセスがアイドルでない場合、この値は0になります。 なぜなら、リクエストの処理が終わった時にこの値は計算されるからです。

注意:

プールに特有の全ての値は、FPM が再起動されるとリセットされます。

注意:

OpenMetrics フォーマットの出力は、 OpenMetrics に準拠した、異なるパラメータタイプを使います。 出力のパラメータとその説明は、 OpenMetrics フォーマット出力に含まれています。

変更履歴

バージョン 説明
8.1.0 openmetrics フォーマットが追加されました。
add a note

User Contributed Notes 4 notes

up
16
uwe at ohse dot de
1 year ago
Before someone else misunderstands that:
"request duration The total time in seconds spent serving requests."

This is not the total time of all requests done by that process, but either the time used by the last request done (idle state), or the current request (all other states).

And the number given is not in seconds, but in microseconds.

The fpm status documentation is a mess.
up
1
Anonymous
7 months ago
there is an error in the docs, if you want to use with fastcgi, the correct link in ProxyPass is not

ProxyPass "unix:/var/run/php-fpm.sock|fcgi://localhost/fpm-status"

but only

ProxyPass "unix:/var/run/php-fpm.sock|fcgi://localhost"

otherwise the page says "File not found"
up
1
Mark Gooderum
2 months ago
Anonymous is correct.

So the URI has to match the pm.status_path in the pool configuration and in turn the Apache Location configuration. The same applies to ping.path.

Ergo If you want multiple PHP FPMs exposed on the same Apache each needs their own unique path. Also from experience Apache 8 FPM status_listen doesn't seem to work with the domain socket, only TCP. Obviously for 8.x you'll need unique port numbers for each PHP FPM and they need to match between the pm.status_listen and the Apache ProxyPass line.

So imagine I want FPM status and ping exposed for 7.4 and 8.2.

I then have an Apache config like:

<LocationMatch "/fpm-ping-74">
Order Deny,Allow
Require local
ProxyPass "unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
</LocationMatch>
<LocationMatch "/fpm-status-74">
Order Deny,Allow
Require local
IncludeOptional trusted-ips.conf
ProxyPass "unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
</LocationMatch>

<LocationMatch "/fpm-ping-82">
Order Deny,Allow
Require local
IncludeOptional trusted-ips.conf
ProxyPass "unix:/run/php/php8.2-fpm.sock|fcgi://localhost:9002"
</LocationMatch>
<LocationMatch "/fpm-status-82">
Order Deny,Allow
Require local
ProxyPass "unix:/run/php/php8.2-fpm.sock|fcgi://localhost:9002"
</LocationMatch>

Then in the respective pool config files:

7.4/fpm/pool.d/www.conf:

; status_listen default works in 7.4
pm.status_path = /fpm-status-74
ping.path = /fpm-ping-74

8.2/fpm/pool.d/www.conf:

; Need an explicit TCP listen in 8.x - why?
pm.status_listen = 127.0.0.1:9002
pm.status_path = /fpm-status-82
ping.path = /fpm-ping-82
up
0
ninsuo
25 days ago
For caddy 2, you may use the following configuration:

http://localhost {
root * /var/www/public

reverse_proxy /status php_fpm:9000 {
transport fastcgi {
env SCRIPT_NAME /status
}
}

encode gzip zstd

php_fastcgi php_fpm:9000
file_server
}

Replace php_fpm:9000 by the host/port of your php fpm or the path of your unix// socket.
To Top