Issue with variables in access_log and error_log

Dale Gallagher dale.gallagher at
Wed Jul 29 21:55:09 MSD 2009

Dale Gallagher wrote:
> access_log $webroot/$domain/log/access.log;
> error_log $webroot/$domain/log/error.log error;

I've just seen the other post about error_log not supporting
variables, so changed the config to that below.

    error_log /var/www/default/log/error.log error;

    set $webroot /var/www;

    set $domain $host;
    # remove www hostname, if there
    if ($domain ~ "^(w{3}\.)?(.*)") {
      set $domain $2;

    open_log_file_cache max=1000;
    access_log /var/www/$domain/log/access.log;

I had to omit the use of $webroot as the first part of the access_log
path because nginx prepended /usr and the moaned about permission
denied (obviously). ie. it was:

  access_log $webroot/$domain/log/access.log

... which nginx expanded to /usr//var/ww/$domain/log/access.log

so I had to hard-code the config as:

  access_log /var/www/$domain/log/access.log

Is the above a bug perhaps, or something to do with how I built nginx?
It seems if there isn't a '/' at the beginning of the path (before the
variables are expanded) that /usr is prepended.

Lastly, why include support for variable expansion in access_log, but
not error_log. I'm curious.


More information about the nginx mailing list