4

I want to split the nginx error.log by date, but not work

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 :

enter image description here

Steven Liang
  • 355
  • 3
  • 10
HEXB
  • 61
  • 1
  • 7

2 Answers2

0

According to this thread, using variables in error_log directive is not allowed.

It's so by design. Variables are only available with HTTP requests, while error_log is not limited to HTTP.

However you can use logrotate or create a script that do the renaming for you, check the following related question from ServerFault

Mostafa Hussein
  • 11,063
  • 3
  • 36
  • 61
0

Add your block into the server{} block and it should work.

Junaid
  • 1