An apache log configuration example

  • 2020-05-06 12:09:42
  • OfStack

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

Add or modify to:


ErrorLog "logs/www.7755gg.com-error_log"
ErrorLog "/data/home/777logs/www.7755gg.com-error_log"
CustomLog "logs/www.7755gg.com-access_log" common
CustomLog "|/usr/local/apache2/bin/rotatelogs  /data/home/7755logs/%Y%m%d-access_log 86400 400M" combined

Explanation:
1) one log file per day, stored in /data/home/777logs.
2) round-trip storage. The file name is named after the date of each day.

2, mkdir data/home logs

/ 7755

3. Automatically delete expired log files:
vim /data/home/crontabfile/clean_apache_log


#! /bin/bash
/usr/bin/find  /data/home/777logs/ -name "*access*"  -mmin +21600 -exec rm  {} \;

Explanation:
/usr/bin/find   /data/home/777logs/ -name "*access*"   -mmin +21600 -exec rm   {} \;
In /data/home777logs/ find modification time before 21600 minutes to include access file and delete.

4,


crontab -e
11 00 * * *  /data/home/crontabfile/clean_apache_log
/etc/init.d/crond resrtart


Related articles: