← 归档

$ cat 通过变量设.md

通过设置变量切割nginx日志

记录
文章目录

在http中

如果要在http块中设置access_log,可以使用map设置变量

1
2
3
4
map $time_iso8601 $logdate {
'~^(?<ymd>\d{4}-\d{2}-\d{2})' $ymd;
default 'date-not-found';
}

日志路径

1
access_log logs/$logdate-access.log;

在server或location中

定义变量

1
2
3
4
5
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
}

日志路径

1
access_log logs/$year-$month-$day-access.log;

输入关键词,查找这里的点滴记录。