有多个vhost在apache 2.2.22(Ubuntu 12.04)上运行,我想将每个vhost错误日志发送到单独的rsyslog文件,以下是配置
阿帕奇幽灵
<VirtualHost *:80>
php_value auto_prepend_file sdemoqa.php
DocumentRoot /home/www//demoqa
ServerName sdemoqa.xyz.com
ErrorLog "syslog:local1"
CustomLog /var/log/apache/sdemoqa-access.log combined
RewriteEngine on
Include /nas/wow.conf
Include /nas/auth.conf
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/www/demoqa/hearing
ServerName shdemoqa.xyz.com
# ErrorLog /var/log/apache/hdemoqa-error.log
ErrorLog "syslog:local2"
CustomLog /var/log/apache/shdemoqa-access.log combined
</VirtualHost>
Syslog config/etc/rsyslog.d/50-default.conf
#Mod Security Logs
local1.* /var/log/apache2/modsec/sdemoqa.log
local2.* /var/log/apache2/modsec/shdemoqa.log
但是所有 vhosts 错误都会重定向到 apache 配置中提到的系统日志的第一个条目。我的意思是两个vhosts错误日志都将转到"local1.*/var/log/apache2/modsec/sdemoqa.log"
谢谢infosec.pk
日志记录指令的syslog
位置仅适用于ErrorLog
指令,并且日志工具是全局的。 最后定义者是将用于所有syslog
日志记录位置的设施点。
正如建议的那样,原木管道是实现您所描述的原木管道的最佳方法。 这是不幸的,因为您失去了区分优先级的能力。
此外,其他答案表明记录器位于我安装的 Ubuntu 12.04 的/bin/logger
,它实际上位于 /usr/bin/logger
<VirtualHost *:80>
php_value auto_prepend_file sdemoqa.php
DocumentRoot /home/www//demoqa
ServerName sdemoqa.xyz.com
CustomLog "|/usr/bin/logger -p local1.notice -t apache" common
CustomLog /var/log/apache/sdemoqa-access.log combined
RewriteEngine on
Include /nas/wow.conf
Include /nas/auth.conf
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/www/demoqa/hearing
ServerName shdemoqa.xyz.com
CustomLog "|/usr/bin/logger -p local2.notice -t apache" common
CustomLog /var/log/apache/shdemoqa-access.log combined
</VirtualHost>
我通过管道传输了两个VirtualHost
声明,假设您希望默认ErrorLog
指令也转到另一个位置的syslog
。
您可能需要使用以下内容修改自定义日志行:
CustomLog "|/bin/logger -p local1.info -t apache" combined
ErrorLog syslog:local1
我认为这里的重点是combined
需要位于每个虚拟主机中第一个日志记录行的末尾,否则它可能会将其与下一个虚拟主机日志组合在一起。 所以正如汤姆提到的那样,或者倒置
ErrorLog syslog:local1 combined
CustomLog "|/bin/logger -p local1.info -t apache"
如果只有两个虚拟主机,则至少在第一个虚拟主机中必须如此,如果有更多虚拟主机,则需要以这种方式排序,并在每个先前虚拟主机的第一个日志记录行末尾combined
,否则下一个虚拟主机将始终合并到先前的虚拟主机日志设置/位置中。
免责声明:我还没有完全测试过这个,在实施之前测试这个......