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 am running nginx version 1.2.8.

It seems that $log and $elog in the below configuration are not expanded, and as a result, nothing is logged. Is that the problem, and how can I get them to expand?

nginx Config:

server {
    listen              xx.xx.xx.xx:80 default;
    server_name         domain.com;
    set                 $docroot                /home/domain.com/public_html;
    set                 $log                    /home/domain.com/logs/access_log;
    set                 $elog                   /home/domain.com/logs/error_log;
    root                $docroot;
    error_log           $elog;
    include             /etc/nginx/http-backend.conf;

}

/etc/nginx/http-backend.conf config:

.....
location ~* ^.+\.(jpg|jpeg|gif|png|svg|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|ico|swf|txt|tgz|tbz|pdfpls|torrent)$ {
    root                $docroot;
    try_files           $uri @fallback;
    access_log          $log            main;
    error_log           $elog;
    expires             30d;
    add_header          Pragma          "public";
    add_header          Cache-Control   "public";
#    error_page         404 = @fallback;
}
.....

UPD: Thanks to Valery Viktorovsky i resolved this by changing permissions to logs folders.

chown -R apache.root /home/*/logs/
chmod -R 750 /home/*/logs/

Mentioned workaround, slightly modified, has been applied also. It doesn't work without it, even with right permissions. Values of $log and $elog remains unchanged, but the slash is added.

Updated /etc/nginx/http-backend.conf config:

.....
location ~* ^.+\.(jpg|jpeg|gif|png|svg|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|ico|swf|txt|tgz|tbz|pdfpls|torrent)$ {
    root                $docroot;
    try_files           $uri @fallback;
#    access_log          $log            main;
#    error_log           $elog;
    access_log          /$log            main;
    error_log           /$elog;
    expires             30d;
    add_header          Pragma          "public";
    add_header          Cache-Control   "public";
#    error_page         404 = @fallback;
}
.....

There is still a problem, because apache creates log files with owner root. To partially solve this, same commands have been added to logrotate config:

/home/*/logs/*_log {
    missingok
    notifempty
    weekly
    minsize 50M
    compress
    rotate 60
    sharedscripts
    postrotate
        /sbin/service nginx reload > /dev/null 2>/dev/null || true
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
        chown -R apache.root /home/*/logs/ > /dev/null 2>/dev/null || true
        chmod -R 750 /home/*/logs/ > /dev/null 2>/dev/null || true
    endscript
}
share|improve this question

1 Answer 1

up vote 0 down vote accepted

nginx workers must have rights to create files in /home/domain.com/logs

So check permissions for /home/domain.com/logs directory.

Also you can use small workaround:

server {
    set        $log                    'home/domain.com/logs/access_log';
    access_log  /$log;
}
share|improve this answer
    
Thank you for pointing me to right direction. I misunderstood that part regarding permissions on log folder. –  mra4nii May 18 '13 at 1:55

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.