LoginSignup
8
6

More than 5 years have passed since last update.

Nginx基礎 ログ 設定いろは

Posted at

アクセスログ(とか)をTSVにしてみる

apacheとかと同じですね。log_formatにcommon(なんでもいい)という名前を付けてそれを出力したいログに対して設定しています。
ちなみに以下では「http_x_forwarded_for」などカスタムヘッダも出力する設定です。

log_format common '$remote_addr\t-\t$remote_user\t[$time_local]\t'
                    '"$request"\t$status\t$body_bytes_sent\t'
                    '"$http_referer"\t"$http_user_agent"\t$http_x_forwarded_for\t$request_time';

    location /hoge {
        access_log  /var/log/nginx/site_hoge/access.log common;
        error_log   /var/log/nginx/site_hoge/error.log;

        proxy_pass  http://xxxxx;
    }

404をエラーとしない

デフォルトだと404のアクセスログ+エラーログが出力され無駄?なエラーログが増えてしまいます。

location / {
log_not_found off;
}

アクセスログださない

    location / {
        access_log off;
    }

反映

設定変更がおわったらお決まりの serviceのreload もしくは restartをしてあげて完了です。(# servcie nginx reload)

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6