由于公司服务器上挂的网站太多,apache访问日志一不小心,就变得超肥(好几个G),不进行日志拆分的话,严重影响网站访问速度和服务器性能(猜的)。没时间解释了,直接上配置:
conf/httpd.conf 添加或修改配置:可以先搜索下CustomLog关键词,这里配置的是一天一个日志文件:
CustomLog "|bin/rotatelogs logs/access_%Y-%m-%d.log 86400 480" combined
CustomLog "|bin/rotatelogs logs/access_%Y-%m-%d.log 86400 480" combined
httpd.conf日志相关配置代码片段(百分之99都是默认配置),我确定我只动了CustomLog这行配置:
<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
CustomLog "|bin/rotatelogs logs/access_%Y-%m-%d.log 86400 480" combined
#
# 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>
这里配置的是访问日志分割,错误日志是 ErrorLog , 配置方式理论上应该一样。
combined 或 common 是指定日志内容格式,别问我怎么知道的,自己琢磨!combined 日志信息更全一点,不信自己配置看。
httpd.conf 配置修改好后,重启apache服务,随便访问个网站,看看日志文件:
完美,过两天可以再过来看一眼!我用的Apache2.2