简体   繁体   English

如何按日期分割Nginx error.log?

[英]How do i can split nginx error.log by date?

I want to split the nginx error.log by date, but not work 我想按日期拆分nginx error.log,但不起作用

here is my code : 这是我的代码:

if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
    set $year $1;
    set $month $2;
    set $day $3;
}
access_log logs/access.log.$year$month$day main;
error_log  logs/error.log.$year$month$day;

but the result is : 但结果是:

在此处输入图片说明

According to this thread , using variables in error_log directive is not allowed. 根据此线程 ,不允许在error_log指令中使用变量。

It's so by design. 是设计使然。 Variables are only available with HTTP requests, while error_log is not limited to HTTP. 变量仅适用于HTTP请求,而error_log不仅限于HTTP。

However you can use logrotate or create a script that do the renaming for you, check the following related question from ServerFault 但是,您可以使用logrotate或创建为您进行重命名的脚本,请从ServerFault中检查以下相关问题

将您的块添加到server {}块中,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM