Include date in nginx log file name

前端 未结 1 539
忘掉有多难
忘掉有多难 2021-02-11 01:07

I am running nginx 1.15.6 and I am trying to include the current date in the nginx log file name.

Some thing like this: access_log /var/log/nginx/access.2018.11.07.log

1条回答
  •  佛祖请我去吃肉
    2021-02-11 01:40

    This is what I ended up using and it works perfectly:

    map $time_iso8601 $year {
        default '0000';
        "~^(\d{4})-(\d{2})-(\d{2})" $1;
    }
    map $time_iso8601 $month {
        default '00';
        "~^(\d{4})-(\d{2})-(\d{2})" $2;
    }
    map $time_iso8601 $day {
        default '00';
        "~^(\d{4})-(\d{2})-(\d{2})" $3;
    }
    
    access_log  /var/log/nginx/access.$year-$month-$day.log  apm_json;
    

    0 讨论(0)
提交回复
热议问题