Using dynamic access_log, automatically create parent directory

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?

Seems like this should be default behavior?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,260563,260563#msg-260563

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.

f

Francis D. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs