1

apache 2.2.22(Ubuntu 12.04)上有多个 vhost 正在运行,我想将每个 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>

系统日志配置 /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 配置中提到的 syslog 的第一个条目。我的意思是两个虚拟主机错误日志都将转到“local1.* /var/log/apache2/modsec/sdemoqa.log”

感谢 infosec.pk

4

3 回答 3

3

日志记录指令的syslog位置仅适用于该ErrorLog指令,并且日志工具是全局的。最后定义的都是将用于所有syslog日志记录位置的设施。

正如建议的那样,日志管道是实现您所描述的内容的最佳方式,这就是日志管道已经提到的内容。这是不幸的,因为您失去了区分优先级的能力。

此外,其他答案表明记录器位于/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另一个位置,因此我对这两个声明进行了管道传输。

于 2013-12-15T13:26:10.163 回答
0

您可能需要使用以下内容修改您的 customlog 行:

CustomLog "|/bin/logger -p local1.info -t apache" combined
ErrorLog syslog:local1
于 2013-09-05T18:41:04.687 回答
-1

我认为这里的重点是combined需要在每个 vhost 的第一个日志记录行的末尾,否则它可能会将它与下一个 vhost 日志结合起来。因此,正如汤姆所提到的那样,或者正如 OP 所要求的那样:

ErrorLog syslog:local1 combined
CustomLog "|/bin/logger -p local1.info -t apache"

如果只有两个 vhost,则至少在第一个 vhost 中必须是这种方式,如果还有更多,则需要combined在每个前一个 vhost 的第一个日志记录行的末尾以这种方式排序,否则下一个 vhost 将始终得到合并到之前的 vhost 日志设置/位置。

免责声明:我尚未对此进行全面测试,请在实施之前对其进行测试...

于 2013-11-08T18:01:20.347 回答