1、# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 

修改日志文件为:

ErrorLog "logs/test.com-error_log"       错误日志

CustomLog "logs/test.com-access_log" combined  访问日志  相对路径


Apache的common日志格式定义:

# vim /usr/local/apache2/conf/httpd.conf

<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>

%h:客户机的IP地址

%l:客户机登陆名称

%u:认证用户

%t:访问的日期、时间

%r:客户访问的方式,访问的什么资源,什么协议

%>s 请求对应的状态码  #2开头正常,3开头被重定向,4开头客户端存在错误,5开头服务器端遇到错误

%b:传送的字节数

%{Referer}:   从哪个页面来的(比如从百度搜索到的QQ空间,那Referer就是百度

%{User-Agent}:客户用的什么浏览器

# tail -10 test.com-access_log

192.168.101.175 - - [01/Dec/2015:14:36:52 +0800] "GET /misc.php?mod=patch&action                                                 =pluginnotice&inajax=1&ajaxtarget=plugin_notice HTTP/1.1" 200 63


每天都会有大量的日志,该怎么处理呢?

# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf

ErrorLog "logs/test.com-error_log"

CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com-access_%Y%m%d_log 86400" combined

86400s==一天

# ls /usr/local/apache2/logs       此时日志按照天分割

test.com-access_20151214_log  test.com-error_log


Apache如何做到不记录指定文件类型日志?

# !vim

vim /usr/local/apache2/conf/extra/httpd-vhosts.conf

    SetEnvIf Request_URI ".*\.gif$" p_w_picpath-request

    SetEnvIf Request_URI ".*\.jpg$" p_w_picpath-request

    SetEnvIf Request_URI ".*\.png$" p_w_picpath-request

    SetEnvIf Request_URI ".*\.bmp$" p_w_picpath-request

    SetEnvIf Request_URI ".*\.swf$" p_w_picpath-request

    SetEnvIf Request_URI ".*\.js$" p_w_picpath-request

    SetEnvIf Request_URI ".*\.css$" p_w_picpath-request

    ErrorLog "logs/test.com-error_log"

    CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/test.com-access_%Y%m%d_log 86400" combined env=!p_w_picpath-reqest