Nginx docker (13: Permission denied) while logging request to mounted volume

Nginx docker (13: Permission denied) while logging request to mounted volume

我使用的nginx版本:nginx/1.11.8

我的 docker 文件如下所示:

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 ; set $month ; set $day ; }
  access_log /var/log/nginx/nginx.$hostname.$year-$month-$day.log logs;
}

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

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

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

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

原来是 location 块中的 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 ; set $month ; set $day ; }

    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;
    }
  }
}