1

This is my default.conf. I specify the access.log and error.log path. And I use docker to build it.

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

When I builded it and up. I got the error message.

nginx_1  | nginx: [emerg] open() "/var/log/nginx/test2/error.log" failed (2: No such file or directory)

How can I automatically generate the file path? This is my docker-compose, Github

1 Answer 1

1

The error you are getting is because the test2 directory doesn't exists. Nginx will not create this automatically for you. So you need to create it using below commands in your Dockerfile

RUN mkdir -p /var/log/nginx/test2 /var/log/nginx/test
Sign up to request clarification or add additional context in comments.

2 Comments

I know I need to create the folder first. Can I auto generate the folder?
No, because nginx won't start without the folder being there. So either you put a SH file which does that and launch nginx.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.