s %b \"%{Referer}i\" \"%{User-Agent}i\"\" combined LogFormat \"%h %l %u %t \"%r\" %>s %b\" common CustomLog \"/usr/logs/logs/access_log\" combined 然后,这样的话当前的虚拟主机的日志就会放到/usr/logs/">

apache 记录来访日志,并按照日期进行分割

  • 来源:
  • 更新日期:2018-05-08

摘要:首先,我是逐个对每个虚拟主机进行配置的,找到一个虚拟主机,添加如下内容 LogFormat \"%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"\" combined LogFormat \"%h %l %u %t \"%r\" %>s %b\" common CustomLog \"/usr/logs/logs/access_log\" combined 然后,这样的话当前的虚拟主机的日志就会放到/usr/logs/

首先,我是逐个对每个虚拟主机进行配置的,找到一个虚拟主机,添加如下内容

 

LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined LogFormat "%h %l %u %t "%r" %>s %b" common CustomLog "/usr/logs/logs/access_log" combined

002UASMrzy7605pjKJv15&690.jpg

 

然后,这样的话当前的虚拟主机的日志就会放到/usr/logs/logs/access_log

具体位置如下:

 

<VirtualHost *:80> ... LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined LogFormat "%h %l %u %t "%r" %>s %b" common CustomLog "/backup/logs/access_log" combined </VirtualHost>

 

如果要添加按照日期进行划分,如下请修改

 

(就是修改这一句:

CustomLog "/backup/logs/access_log" combined )

 

CustomLog "|/usr/local/apache/bin/rotatelogs /backup/logs/abc.%Y%m%d 86400" common

/usr/local/apache/ apache路径

/backup/logs 日志路径

abc 日志前缀

%Y%m%d 后缀格式

86400 分割时长

 

具体日志命名如下:abc.201309135

 

如下部分为啥会有俩,暂时搞不明白,应该下边的可以去掉,请高人指点

 

LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined LogFormat "%h %l %u %t "%r" %>s %b" common