Nginx docker(13:权限被拒绝),同时将请求记录到已装入的卷

时间:2017-02-15 11:12:21

标签: logging nginx docker permissions mounted-volumes

我使用的是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;
}

我的主机日志目录是所有者:steve group:logs

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

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

我是否遗漏了使用变量让它工作的明显事实?

1 个答案:

答案 0 :(得分: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;
    }
  }
}