我正在跟踪AWS指令,以增强对弹性豆茎的健康监测。作为其中的一部分,我需要nginx将一个日志文件输出到相应命名为:/var/log/nginx/healthd:application.log.YYYY.MM.DD.HH中。
出于某种原因,我的nginx不会创建该文件。它能够在该文件夹中创建application.log或aplication.log.1-2-3-4,但不能创建application.log.YYYY.MM.DD.HH。只是不出现而已。没有错误什么的。
我的nginx公司:
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
worker_rlimit_nofile 32634;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [[$time_local]] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
log_format healthd '$msec"$uri"'
'$status"$request_time"$upstream_response_time"'
'$http_x_forwarded_for';
server {
listen 80;
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
}
access_log /var/log/nginx/access.log main;
access_log /var/log/nginx/healthd/application.log healthd; #works!
access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd; #doesn't!
location / {
...
}
}
}我认为这是日期的问题,但我用以下方法打印出来:
location /temp {
return 200 "/var/log/nginx/healthd/application.log.$year-$month-$day-$hour";
}并得到正确的字符串:/var/log/nginx/healthd/application.log.2021-01-29-15。
是什么导致了这一切?
发布于 2021-01-31 06:24:30
不直观(但正确)的答案被描述为这里和TLDR,这与nginx的属性有关:
在每次写入日志期间,都会检查请求根目录的存在,如果不存在,则不会创建日志。
一旦您设置了nginx可以找到的根目录,一切都会按预期工作。
感谢@Anton的链接。
https://stackoverflow.com/questions/65957748
复制相似问题