デバッグログ

選択されたクライアントのデバッグログ
循環メモリバッファへのログ

デバッグログを有効にするには、ビルド時にnginxをデバッグサポートするようにconfigureする必要があります。

./configure --with-debug ...

そしてdebugレベルはerror_logディレクティブを使って設定されなければなりません。

error_log /path/to/log debug;

デバッグをサポートするようにnginxが設定されているかを確認するには、nginx -V コマンドを実行してください。

configureの引数: --with-debug ...

事前ビルドされた Linux パッケージは以下のコマンドを使って実行することができる nginx-debug バイナリ (1.9.8) のデバッグログをそのまま使えるサポートを提供します。

service nginx stop
service nginx-debug start

そして、 debug レベルを設定します。nginxのWindowsのバイナリバージョンは常にデバッグログサーポートで構築されます。そのため debug レベルの設定だけで十分です。

debug レベルの指定無しでログを再定義してもデバッグログは無効になることに注意してください。以下の例では、serverレベルのログの再定義がこのサーバのデバッグログを無効にしています。

error_log /path/to/log debug;

http {
    server {
        error_log /path/to/log;
        ...

これを避けるには、ログの再定義の行をコメントアウトするか、debug レベル指定の追加も必要です。

error_log /path/to/log debug;

http {
    server {
        error_log /path/to/log debug;
        ...

選択されたクライアントのデバッグログ

選択されたクライアントのアドレス だけのデバッグログを有効にすることもできます:

error_log /path/to/log;

events {
    debug_connection 192.168.1.1;
    debug_connection 192.168.10.0/24;
}

循環メモリバッファへのログ

デバッグログは循環メモリバッファに書き込むことができます:

error_log memory:32m debug;

debugレベルのメモリバッファへのログは高負荷のもとでもパフォーマンスに大きな影響はありません。この場合、以下のように gdb スクリプトを使ってログを抽出することができます:

set $log = ngx_cycle->log

while $log->writer != ngx_log_memory_writer
    set $log = $log->next
end

set $buf = (ngx_log_memory_buf_t *) $log->wdata
dump binary memory debug_log.txt $buf->start $buf->end

TOP
inserted by FC2 system