在 Centos 7 上更改 Apache 2.4.x 的日志文件目录

在 Centos 7 上更改 Apache 2.4.x 的日志文件目录

目前我的日志文件位于 `/var/log/httpd/ 下。由于我的根分区数量有限,日志超出了限制并导致系统卡住。

我想将 apache 日志目录更改为另一个已安装的卷。

我没有改变并发现有关配置文件中的日志文件目录的任何信息,将目录更改/var/log/http/*为的最简单方法是什么/someRandomVolume/httpLogFolder/*

这就是我在配置文件中记录的内容;

#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog "logs/error_log"

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

<IfModule log_config_module>
    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    #
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    #CustomLog "logs/access_log" common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    CustomLog "logs/access_log" combined
</IfModule>

答案1

在 RHEL/CentOS 上,日志文件的默认位置与ServerRoot 基目录/etc/httpd/,通常是一个从/etc/httpd/logs到 的符号链接/var/log/httpd

如果您想使用不同的目录,只需移动/var/log/httpd并更新该符号链接。

或者,正如@TomTomTom 建议的那样,在CustomLogErrorLog 指令中使用绝对路径。

如果您启用了 SELinux,请确保为新目录设置/保留正确的上下文。

相关内容