Apache2 如何将Apache错误记录到每个虚拟主机的不同系统日志设施中?

Apache2 如何将Apache错误记录到每个虚拟主机的不同系统日志设施中?,apache2,vhosts,error-log,rsyslog,Apache2,Vhosts,Error Log,Rsyslog,apache 2.2.22(Ubuntu 12.04)上运行着多个vhost,我想将每个vhost错误日志发送到单独的rsyslog文件, 以下是配置 阿帕奇Vhost <VirtualHost *:80> php_value auto_prepend_file sdemoqa.php DocumentRoot /home/www//demoqa ServerName sdemoqa.xyz.com ErrorLog "syslog:local1" CustomL

apache 2.2.22(Ubuntu 12.04)上运行着多个vhost,我想将每个vhost错误日志发送到单独的rsyslog文件, 以下是配置

阿帕奇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>
但所有vhosts错误都重定向到apacheconfigs中提到的syslog的第一个条目。 我的意思是两个vhosts错误日志都将指向“local1.*/var/log/apache2/modsec/sdemoqa.log”

谢谢
infosec.pk

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

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

我认为这里的要点是,
合并后的
需要位于每个vhost中第一条日志记录行的末尾,否则它可能会与下一条vhost日志合并。正如Tom所提到的,或者按照OP的命令颠倒过来:

ErrorLog syslog:local1 combined
CustomLog "|/bin/logger -p local1.info -t apache"
如果只有两个虚拟主机,则必须至少在第一个虚拟主机中采用这种方式,如果有更多虚拟主机,则需要以这种方式订购,并在每个先前虚拟主机的第一条记录行末尾使用
组合
,否则下一个虚拟主机将始终组合到先前的虚拟主机日志设置/位置


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

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

正如所建议的,日志管道是实现您所描述的日志管道的最佳方法。这很不幸,因为您失去了区分优先级的能力

此外,其他答案表明,在我安装的Ubuntu 12.04上,logger位于
/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>

php_value auto_prepend_文件sdemoqa.php
DocumentRoot/home/www//demoqa
服务器名sdemoqa.xyz.com
CustomLog“|/usr/bin/logger-p local1.notice-t apache”通用
CustomLog/var/log/apache/sdemoqa-access.log组合
重新启动发动机
包括/nas/wow.conf
包括/nas/auth.conf
DocumentRoot/home/www/demoqa/hearing
服务器名shdemoqa.xyz.com
CustomLog“|/usr/bin/logger-p local2.notice-t apache”通用
CustomLog/var/log/apache/shdemoqa-access.log组合

我通过管道传输了这两个
VirtualHost
声明,假设您希望默认的
ErrorLog
指令也转到另一个位置的
syslog

这不是多余的吗
ErrorLog syslog:local1
语句将发送到本地syslog系统。我记得
CustomLog
这不是为了定义临时日志模式吗?没有提到对将
与ErrorLog组合使用的支持
<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>