在Nginx日志文件名中包含日期 [英] Include date in nginx log file name

查看:562
本文介绍了在Nginx日志文件名中包含日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行nginx 1.15.6,并且试图将当前日期包括在nginx日志文件名中.

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

类似这样的东西:access_log/var/log/nginx/access.2018.11.07.log main;

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

有人知道该怎么做吗?

推荐答案

这是我最终使用的,并且效果很好:

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;

这篇关于在Nginx日志文件名中包含日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆