nginxログ(access_log、log_format、open_log_file_cache、log_not_found、log_subrequest)設定方法

1.access_log
説明:
access_log path [format [buffer=size [flush=time]]];
access_log path format gzip[=level] [buffer=size] [flush=time];
access_log syslog:server=address[,parameter=value] [format];
access_log off;
デフォルト:access_log logs/access.log combined;

2.log_format
説明:
log_format name string …
デフォルト:
log_format combined  "…";

フォーマット1
log_format combined '$remote_addr – $remote_user [$time_local] '
' “$request" $status $body_bytes_sent '
' “$http_referer" “$http_user_agent" ';
フォーマット2
log_format porxy '$http_x_forwarded_for – $remote_user [$time_local] '
' “$request" $status $body_bytes_sent '
' “$http_referer" “$http_user_agent" ';

設定例:
http {
log_format main '$remote_addr – $remote_user [$time_local] “$request" '
'"$status" $body_bytes_sent “$http_referer" '
'"$http_user_agent" “$http_x_forwarded_for" '
'"$gzip_ratio" $request_time $bytes_sent $request_length’;

log_format srcache_log '$remote_addr – $remote_user [$time_local] “$request" '
'"$status" $body_bytes_sent $request_time $bytes_sent $request_length '
'[$upstream_response_time] [$srcache_fetch_status] [$srcache_store_status] [$srcache_expire]’;

open_log_file_cache max=1000 inactive=60s;

server {
server_name ~^(www\.)?(.+)$;
access_log logs/$2-access.log main;
error_log logs/$2-error.log;

location /srcache {
access_log logs/access-srcache.log srcache_log;
}
}
}
3.open_log_file_cache
説明:
open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time];
open_log_file_cache off;
デフォルト:
open_log_file_cache off;

設定例:
open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;

4.log_not_found
説明:
log_not_found on | off;
デフォルト:
log_not_found on;

5.log_subrequest
説明:
log_subrequest on | off;
デフォルト:
log_subrequest off;
6.rewrite_log
説明:
rewrite_log on | off;
デフォルト:
rewrite_log off;

7.error_log
説明:
error_log file | stderr | syslog:server=address[,parameter=value] [debug | info | notice | warn | error | crit | alert | emerg];

デフォルト:
error_log logs/error.log error;

Nginx

Posted by arkgame