Using dynamic access_log, automatically create parent directory

Francis Daly francis at
Tue Jul 28 22:45:33 UTC 2015

On Sun, Jul 26, 2015 at 10:49:01PM -0400, justink101 wrote:

Hi there,

> We use a dynamic value for access logs:
>     access_log /var/log/nginx/domains/$host/access.log main;
> However, if the $host directory does not exist in /var/log/nginx/domains
> nginx fails with an error creating the access log. Is there a way to have
> nginx create the $host directory automatically instead of failing?

Not in stock nginx.

You could create a patch to do it; but I suspect that the overhead of
an extra "mkdir -p"-like call for every log line written would not be
worth it.

If you are willing to rearrange your log file structure such that the
variable part is in the filename, and not a parent directory name,
then stock nginx can help you.

> Seems like this should be default behavior?

I think "no".

But it's the person who writes the code who has the opinion that matters;
at least for their local version of nginx.

Francis Daly        francis at

More information about the nginx mailing list