Apache访问日志切割
[root@daixuan ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf?
修改日志文件為:
ErrorLog "logs/test.com-error_log" ? ? ??logs目錄位置是相對(duì)于/usr/local/apache2
CustomLog "logs/test.com-access_log" combined
Apache的common日志格式定義:
[root@daixuan ~]# 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 ? ? ? ? ? 來(lái)源IP 192.168.101.175
%u ? ? ? ? ? 用戶(hù) ?user1
%t ? ? ? ? ? 時(shí)間 ?
\"%r\" ? ? ? ?動(dòng)作,get
"%{Referer}i\" ? 鏈接地址
"%{User-Agent}i ?瀏覽器的Agent
[root@daixuan logs]# 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
每天都會(huì)有大量的日志,該怎么處理呢?
[root@daixuan logs]# 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==一天
[root@daixuan logs]# ls /usr/local/apache2/logs ? ? ? 此時(shí)日志按照天分割
test.com-access_20151201_log ?test.com-error_log
Apache如何做到不記錄指定文件類(lèi)型日志?
[root@daixuan logs]# !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
文件結(jié)尾不是:gif,jpg,png......才會(huì)記錄到日志中。
[root@daixuan logs]# apachectl -t
Syntax OK
[root@daixuan logs]# apachectl restart
重新訪問(wèn)瀏覽器,打開(kāi)幾個(gè)測(cè)試頁(yè)面,查看日志,發(fā)現(xiàn)gif,jpg,png....結(jié)尾的文件都沒(méi)有記錄到日志
轉(zhuǎn)載于:https://blog.51cto.com/daixuan/1718457
總結(jié)
以上是生活随笔為你收集整理的Apache访问日志切割的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Redhat7 systemctl命令
- 下一篇: 1-6-Xmanager远程工具的使用