Issue with variables in access_log and error_log

Igor Sysoev is at
Wed Jul 29 22:41:46 MSD 2009

On Wed, Jul 29, 2009 at 07:55:09PM +0200, Dale Gallagher wrote:

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

Since 0.7.44 you may use 

      server_name  ~^(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.

This is a bug. Currently this works as expected only for

root   $var;

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

First of all, I personally never use access_log with variables.
However, I use separate access_log's for servers. As to error_log I usually
use single log for all sites, since nginx logs enough information required
to identify server: "server: ..., host: ...". I prefer to look problems
in single place.

Igor Sysoev

More information about the nginx mailing list