log_format 有個默認的日志格式:
log_format combined '$remote_addr - $remote_user [$time_local] ' ' "$request" $status $body_bytes_sent ' ' "$http_referer" "$http_user_agent" ';
nginx 默認調用 combined 格式來記錄日志,即默認調用:(默認記錄在access.log文件中)
access_log logs/access.log combined;
nginx允許自定義日志格式,例如:
log_format main '$remote_addr - $remote_user [$time_local] "$http_host" "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for $request_time';
以上是自定義了日志格式:main(main名稱可以自定義)
要想使其生效,就必須用access_log指定調用:
access_log logs/xx.log main;
否則,nginx仍然會去調用combined格式來記錄日志。
注意,http段也必須明確指定調用main格式才會生效,否則還是會調用默認的combined格式。
(我就曾經犯傻,http段沒有調用main格式,卻一直搞不懂為啥默認日志文件access.log里邊沒有生效!)