The access log in nginx

I configured several virtual hosts in nginx 1.0.14 using regular expression, and configured dedicated access log for every hosts in /var/log. but the following error message is always displayed in nginx-error.log.

2012/09/02 21:03:28 [crit] 846#0: *70 open() "/usr/local/etc/nginx//var/log/cdxmlxx.com-access.log" failed (2: No such file or directory) while logging reques

The following is the core code in nginx.conf

Code:
        server {
                listen          80;
                index           index.php index.html;
                server_name     ~^(www\.)?(.+)$;
                set             $www_root /usr/local/www/$2;
                root            $www_root;
                set             $access_log /var/log/$2-access.log;
                access_log      $access_log;

                location ~ \.php$ {
                        fastcgi_pass    127.0.0.1:9000;
                        fastcgi_index   index.php;
                        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        fastcgi_param  PATH_INFO        $fastcgi_script_name;
                        include        fastcgi_params;
                }
        }

Anybody can help me?
 
I'm not sure why $2 is getting populated with a path, which is part of the problem. Nginx documentation has this example you can try for the capture.

Code:
server {
  server_name   ~^(www\.)?(?<domain>.+)$;
  root  /sites/$domain;
}

It looks like you're trying to write files to /var/log. As nginx may randomly write files based off of external factors, it would be a good idea to make a directory such as /var/log/nginx and put files in there instead. An alternative would be to use a relative path, then symlink /usr/local/nginx/log to /var/log/nginx or something like that.
 
Hello,

replace

Code:
                set             $access_log /var/log/$2-access.log;
                access_log      $access_log;

with

Code:
access_log /desired_log_dir/$2-access.log;

where desired_log_dir is a directory where user which is running nginx (probably www) should be able to write.
 
Morte said:
I'm not sure why $2 is getting populated with a path, which is part of the problem. Nginx documentation has this example you can try for the capture.

Code:
server {
  server_name   ~^(www\.)?(?<domain>.+)$;
  root  /sites/$domain;
}

It looks like you're trying to write files to /var/log. As nginx may randomly write files based off of external factors, it would be a good idea to make a directory such as /var/log/nginx and put files in there instead. An alternative would be to use a relative path, then symlink /usr/local/nginx/log to /var/log/nginx or something like that.

You are right!:e:e
 
Back
Top