Apache limits the size of error. log files

Source: Internet
Author: User
Tags apache access log apache log tomcat

Step 1: stop all processes of the Apache service and delete the error. log and access. log files in the Apache2/logs/directory.
 

Step 2: Open the httpd. conf configuration file of Apache and find the following two configurations.

 

The code is as follows: Copy code
ErrorLog logs/error. log CustomLog logs/access. log common

 

Directly Comment out and replace it with the following configuration file.

The code is as follows: Copy code

# Restrict the error log file to 1 MB

ErrorLog "| bin/rotatelogs.exe-l logs/error-% Y-% m-% d. log 1M"
 

# Generate an error log file every day

# ErrorLog "| bin/rotatelogs.exe-l logs/error-% Y-% m-% d. log 86400 & Prime;

 
# Restrict access log files to 1 MB

CustomLog "| bin/rotatelogs.exe-l logs/access-% Y-% m-% d. log 1M 1M" common

# Generate an access log file every day

# CustomLog "| bin/rotatelogs.exe-l logs/access-% Y-% m-% d. log 86400 & Prime; common

The above are all generated to the apache installation directory. If you cannot install it on the C drive, we can

Change it

The code is as follows: Copy code

ErrorLog "| c:/apache/bin/rotatelogs.exe x:/d/logs/error _ % Y _ % m _ % d. log 86400 480"
CustomLog "| c:/apache/bin/rotatelogs.exe x:/d/logs/access _ % Y _ % m _ % d. log 86400 480" common

Here, c:/apache/is the log directory behind your apache installation path. We can set it by ourselves. To clear the log, I also need to stop apache and delete it.

Supplement: apache log processing method in linux

The code is as follows: Copy code

# Ls-alh
Total usage 2.9 M
Drwxr-xr-x 2 root 4.0 K March 21 10:46.
Drwxr-xr-x 15 root 4.0 K ..
-Rw-r-1 root 907 K March 27 17:24 access_log
-Rw-r-1 root 31 K March 27 17:23 error_log
-Rw-r-1 root 6 March 21 11:03 httpd. pid
-Rw-r-1 root 29 K March 21 11:03 jk-runtime-status
-Rw-r-1 root 1 March 21 11:03 jk-runtime-status.lock
-Rw-r-1 root 465 K March 27 17:24 mod_jk.log

Log description: access_log, error_log, mod_jk.log
These three logs are common,
And these logs are very large.

Access_log Apache access log
Error_log error log file
Mod_jk tomcat's apache extension module (tomcat-connectors) supports AJP 12/13, JNI, and Loadblance.

Log clearing command:

The code is as follows: Copy code

# Cat/dev/null> access_log
# Cat/dev/null> error_log
# Cat/dev/null> mod_jk.log

You can write the preceding three commands as a shell script and then add them to the crontab to clear them once a day. Of course, you can back up and clear them first.

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.