Apache 访问日志可以分开也可以合并吗?

问题描述 投票:0回答:2

我的问题有点令人困惑,对此感到抱歉。这就是我需要的:

好吧,我有(比方说)3 个网站托管在一个 Apache 上(这些网站在每个

VirtualHost
设置中定义。然后我当前分别记录它们的访问日志,如下所示:

  • /var/log/httpd/website-a.com.access_log
  • /var/log/httpd/website-b.com.access_log
  • /var/log/httpd/website-c.com.access_log

定义这样的东西:

<VirtualHost *:80>
    ServerName website-a.com
    ..
    CustomLog logs/website-a.com.access_log common
    ..
</VirtualHost>

所以一切都很好。但同时,我还希望它们(所有访问日志)完全位于 Apache 的默认本地主机日志文件中(我不知道如何调用该文件)。可能是:

  • /var/log/httpd/access_log (我认为这是默认的)

换句话说,有没有办法(如何)以分离的方式保存访问日志,同时也将所有日志保存在同一个组合文件中?


因此,这将允许我在单独的文件中查看每个访问日志。同时,如果需要的话,我也可以在一个地方看到所有日志。

apache virtualhost access-log
2个回答
3
投票
<VirtualHost *:80>
    ServerName website-a.com
    ..
    CustomLog logs/website-a.com.access_log common
    CustomLog logs/access_log common
    ..
</VirtualHost>

只需将

CustomLog logs/access_log common
添加到每个虚拟主机作为第二个日志文件,apache 就会写入这两个文件。


0
投票

GlobalLog Directive 现已在 Apache HTTP Server 2.4.19 及更高版本中可用。用法示例:

创建文件

/etc/apache2/conf-enabled/globallog.conf
:

GlobalLog /home/WWW/logs/globallog.log vhost_combined

并激活它:

a2enconf globallog
apachectl graceful

不要忘记添加日志轮换规则。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.