1. 背景
默认情况下,nginx 的日志会一直输入到 access.log,长时间运行后会导致这个日志文件过大。
2. 方法
修改 nginx.conf
map $time_iso8601 $logdate {
'~^(?<ymd>\d{4}-\d{2}-\d{2})' $ymd;
default 'date-not-found';
}
access_log logs/access-$logdate.log;
error_log logs/error.log;
将上面的文字放在 http 模块中,然后重启 nginx,就会在 logs 文件夹中生成带有日期格式的日志,每天一个。