我正在运行Nginx版本1.2.8.
以下配置中的$log和$elog似乎没有扩展,因此没有记录任何内容.这是问题,我怎样才能让它们扩展?
Nginx配置:
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配置:
.....
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:感谢Valery Viktorovsky我通过更改日志文件夹的权限来解决这个问题.
chown -R apache.root /home/*/logs/
chmod -R 750 /home/*/logs/
提到的解决方法略有修改,也已应用.没有它,即使拥有正确的权限,它也无法运行. $log和$elog的值保持不变,但是添加了斜杠.
更新了/etc/Nginx/http-backend.conf配置:
.....
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;
}
.....
仍然存在问题,因为apache使用所有者root创建日志文件.
为了部分解决这个问题,在logrotate配置中添加了相同的命令:
/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
}
最佳答案