Configure access logs for Apache and split in one day

Source: Internet
Author: User

[Email protected] abc]# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf

650) this.width=650; "title=" 4.png "alt=" wkiom1xi_sftlbluaai3fnxq3x0375.jpg "src=" http://s3.51cto.com/wyfs02/M01/ 72/69/wkiom1xi_sftlbluaai3fnxq3x0375.jpg "width=" 650 "style=" Padding:0px;margin:0px;vertical-align:top;border: none; "/>

Modified to date-named error logs and access logs

errorlog "|/usr/local/apache2/bin/rotatelogs-l/usr/local/ Apache2/logs/tpp.com-error_%y%m%d.log 86400 "
   setenvif Request_URI ". *\.gif$" image-request
   setenvif Request_uri ". *\.jpg$" IMAGE-REQUEST
   setenvif Request_uri ". *\.png$" IMAGE-REQUEST
   setenvif Request_uri ". *\.bmp$" image-request
    Setenvif Request_uri ". *\.swf$" image-request
   setenvif Request_URI " . *\.js$ "Image-request
   setenvif Request_uri". *\.css$ " IMAGE-REQUEST
customlog "|/usr/local/apache2/bin/rotatelogs-l/usr/local/ Apache2/logs/tpp.com-access_%y%m%d.log 86400 "Combined Env=!image-request

Such as:

650) this.width=650; "title=" 7.png "alt=" wkiom1xjbxadvhy8aamiqoorng8714.jpg "src=" http://s3.51cto.com/wyfs02/M00/ 72/69/wkiom1xjbxadvhy8aamiqoorng8714.jpg "width=" 650 "style=" Padding:0px;margin:0px;vertical-align:top;border: none; "/>

Where commands are in absolute path, Rotatelogs is the split tool,%y%m%d time is split units, 86,400 seconds for one day. Setenv is custom, the following access log can invoke env, which means that files ending in gif, JPG, and so on are not recorded.

Then we detect and load Apache from the new

[Email protected] abc]#/usr/local/apache2/bin/apachectl-tsyntax ok[[email protected] abc]#/usr/local/apache2/bin/ Apachectl Graceful

Then we refresh the next page to see a log generation, such as:

[Email protected] abc]# cd/usr/local/apache2/logs/[[email protected] logs]# Lsaccess_log Dummy-host.example.com-access_log dummy-host.example.com-error_log error_log httpd.pid[[email protected] logs]# Lsaccess_log dummy-host.example.com-access_log dummy-host.example.com-error_log error_log httpd.pid Tpp.com-access_ 20160429.log

Note : The cumulative access log will be more and more, below we write a script to delete the access log one months ago:

[Email protected] logs]# cat/usr/local/apache2/logs/logcron.sh

#! /bin/bash

# Delete Access logs

Keepdays=31

Log_files= "/usr/local/apache2/logs/tpp.com-access"

Rm-f ${log_files}_$ (date + "%y%m%d"--date= "-${keepdays} Day"). Log

Added to the scheduled task, executed 0 points per day:

[Email protected] logs]# CRONTAB-E

XX * * * */bin/bash//usr/local/apache2/logs/logcron.sh




This article is from "Linux rookie" blog, please be sure to keep this source http://490617581.blog.51cto.com/11186315/1768858

Configure access logs for Apache and split in one day

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.