Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have the following default server setup in nginx:

# Default HTTP Server
server {
  listen 80 default;
  server_name _;
  access_log /var/log/nginx/$server_name.access.log;
  error_log /var/log/nginx/$server_name.error.log;

  server_name_in_redirect off;

  location / {
    root   domain.com/public;
    index  index.php;
    try_files $uri index.php;
  }

  location ~     \.(html|jpg|jpeg|gif|png|ico|css2|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
    root /path/to/domain.com/public;
    expires 30d;
    break;
  }

  charset utf-8;

  location ~ \.php$ {
    include /opt/nginx/conf/fastcgi_params;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param  SCRIPT_FILENAME  /path/to/domain.com/public/index.php;   
  }

  location ~ \.(js|ico|gif|jpg|png|css)$ {
    root /path/to/domain.com/public;
  }
}

I have several domains pointing to the server. What I'm trying to accomplish here is to have logs in the format of either /var/log/nginx/mydomain.com/access.log or /var/log/nginx/mydomain.com.access.log

Instead, I am getting /var/log/nginx/$server_name.access.log.

If I try the directory method I get an error when checking the config nginx: [emerg] open() "/var/log/nginx/$server_name/access.log" failed (2: No such file or directory)

Why isn't nginx passing the variable to the file name?

Using nginx/1.0.0

share|improve this question
    
What version are you running? Variables in log filenames are only allowed since 0.7.4. wiki.nginx.org/HttpLogModule –  Frank Farmer Jun 21 '11 at 23:13
1  
and even then, only in access_log. Variables are still not allowed in error_log. $server_name is also probably not the variable you're really looking for, as it will always expand to '_' in your case. You probably were really looking for $host. –  kolbyjack Jun 22 '11 at 13:15
    
I'm using 1.0.0, and thanks for the pointer on $host - that's what I was trying to accomplish. Also, didn't know Server Fault existed - mind blown, thanks for the migration. –  Mahdi.Montgomery Jun 22 '11 at 19:59
add comment

migrated from stackoverflow.com Jun 22 '11 at 9:49

This question came from our site for professional and enthusiast programmers.

1 Answer

up vote 2 down vote accepted

You need to use the $host variable (thanks, @kolbyjack)

share|improve this answer
    
I'll assume there is no work-around for passing a variable for the error_log.. Which is kind of too bad. –  Mahdi.Montgomery Jun 22 '11 at 20:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.