在apache 2.2.22(Ubuntu 12.04)上运行了多个vhost,我想将每个vhost错误日志发送到单独的rsyslog文件,以下是配置
Apache Vhost
<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配置/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 configs中提到的syslog的第一个条目。我的意思是两个vhosts错误日志都将转到“local1。* /var/log/apache2/modsec/sdemoqa.log”
谢谢infosec.pk
日志记录指令的syslog
位置仅适用于ErrorLog
指令,并且日志工具是全局的。无论最后定义的是将用于所有syslog
测井位置的设施。
正如建议的日志管道是实现您所描述的最佳方式,已经提到日志管道。这很不幸,因为你失去了区分优先权的能力。
此外,其他答案建议logger位于/bin/logger
我安装的Ubuntu 12.04它实际上位于/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
需要位于每个vhost中第一个日志行的末尾,否则它可能会将它与下一个vhost日志结合起来。正如汤姆所提到的那样,或者像OP所订购的那样:
ErrorLog syslog:local1 combined
CustomLog "|/bin/logger -p local1.info -t apache"
如果只有两个虚拟主机,那么至少在第一个虚拟主机中必须是这种方式,如果需要在每个先前虚拟主机的FIRST日志行末尾用combined
以这种方式进行排序,否则下一个虚拟主机将始终结合到先前的vhost日志设置/位置。
免责声明:我还没有对此进行全面测试,在实施之前对此进行测试......