这是我的default.conf
。我指定access.log和error.log路径。我使用docker来构建它。
server {
listen 80;
server_name localhost;
root /var/www/html;
index index.html index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
}
access_log /var/log/nginx/test/access-$year-$month-$day.log;
error_log /var/log/nginx/test2/error.log;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
}
当我建造它时。我收到了错误消息。
nginx_1 | nginx: [emerg] open() "/var/log/nginx/test2/error.log" failed (2: No such file or directory)
如何自动生成文件路径?这是我的docker-compose,Github
答案 0 :(得分:0)
您获得的错误是因为test2
目录不存在。 Nginx不会自动为您创建。因此,您需要使用Dockerfile中的以下命令创建它
RUN mkdir -p /var/log/nginx/test2 /var/log/nginx/test