MENU

nginx按日期存放日志

2021 年 11 月 17 日 • linux相关

单文件存放,后面还需要定期手工切割,在配置中设备按日期自动分开存放比较好。

按日期分割

server {
    listen 80;
    server_name abc.com;
        #.....中间省略
    if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
            set $date $1$2$3;
       }
    access_log  /home/wwwlogs/$date.$server_name.log;
}

精细分割

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;
}
返回文章列表 文章二维码
本页链接的二维码
打赏二维码