Log
Ubuntu Nginx Log 建置常用指令
Categories:
Access Log
依照日期储存
$time_iso8601
格式
2014-05-04T18:12:02+02:00
撷取时间 YYYY-MM-DD
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
}
access_log /var/log/nginx/$year-$month-$day-access.log;
使用 Perl 撷取时间
if ($time_iso8601 ~ "^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})") {}
access_log /var/log/nginx/$year-$month-$day-access.log;
撷取 YYYY-MM-DD HH:II:SS
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
set $minutes $5;
set $seconds $6;
}
Log 路径
设定档:
/etc/nginx/nginx.conf
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;