1

我使用的是 nginx 版本:nginx/1.11.8

我的码头文件看起来像:

FROM nginx
COPY website /usr/share/nginx/html/website/
RUN chown -R nginx /usr/share/nginx/html
RUN chown -R nginx /var/log/nginx/
EXPOSE 80

我正在为我的访问日志名称使用变量,如下所示。在没有安装到主机上的目录的情况下运行时,这可以正常工作并生成日志。

location / {
  try_files $uri /index.html;
  if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") { set $year $1; set $month $2; set $day $3; }
  access_log /var/log/nginx/nginx.$hostname.$year-$month-$day.log logs;
}

我的主机日志目录是 owner:steve group:logs

如果我从访问日志名称中删除变量,那么它会正确记录到主机目录,即

access_log /var/log/nginx/nginx.novars.log logs;

我是否遗漏了一些明显的东西来让它使用变量来工作?

4

1 回答 1

0

原来是位置块内的 if 语句导致了问题。这有效,并允许我按日期轮换我的日志文件。

http {
  include /etc/nginx/conf/*.conf;
  include /etc/nginx/mime.types;

server {
  listen       80 default_server;
  root   /usr/share/nginx/html/;
  underscores_in_headers on;

  if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") { set $year $1; set $month $2; set $day $3; }

    location / {
      index  index.html index.htm;
      try_files $uri $uri/ /index.html$query_string;
      access_log /var/log/nginx/nginx.agent-ux.$hostname.$year-$month-$day.log logs;
    }
  }
}
于 2017-11-21T14:03:33.200 回答