The site's access log grows quickly, if saved in a file, do not cut, then quickly burst the server's disk, we need to cut it, and periodically delete useless logs, to ensure the proper use of the disk.
1. Edit the virtual host configuration file
[Email protected] important]# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf
2. Remove the comment in front of the access log configuration line #
<virtualhost *:80>
DocumentRoot "/tmp/123"
ServerName invalid.com
</VirtualHost>
<virtualhost *:80>
DocumentRoot "/data/www"
ServerName www.test.com
Serveralias www.mydiscuz.com
Serveralias www.others.com
Errorlog "Logs/dummy-host.example.com-error_log"
Customlog "Logs/dummy-host.example.com-access_log" combined
<ifmodule mod_rewrite.c>
Rewriteengine on
Rewritecond%{http_host} ^www.mydiscuz.com$ [OR]
Rewritecond%{http_host} ^www.others.com$
Rewriterule ^/(. *) $ http://www.test.com/$1 [r=301,l]
</IfModule>
<Directory/data/www/important/>
AllowOverride authconfig
AuthName "username"
AuthType Basic
authuserfile/data/.htpasswd
Require Valid-user
</Directory>
</VirtualHost>
Where combined is the name of the log format, the main configuration file defines three kinds of log format combined, common, combinedio. We use the combined format here.
3. Reload the configuration file after checking it correctly:
[Email protected] important]# apachectl-t
Syntax OK
[Email protected] important]# Apachectl Graceful
4. Multiple accesses in the browser, you can generate access logs and error logs (empty when there is no error)
[Email protected] important]# cd/usr/local/apache2/logs/
[[email protected] logs]# ls
Access_log Error_log
Dummy-host.example.com-access_log Httpd.pid
Dummy-host.example.com-error_log
To view the log format definition in the master configuration file:
[Email protected] important]# 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>
# need to enable MOD_LOGIO.C to use%I and%O
Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "%I%O" Combinedio
</IfModule>
......
Format Description:
Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" combined
%h Source IP
Use '-' when%l does not exist
%u user name, non-existent with '-' representation
%t time
%r action, GET or post
5. Edit the virtual host configuration file to define how the log is cut:
<virtualhost *:80>
DocumentRoot "/tmp/123"
ServerName invalid.com
</VirtualHost>
<virtualhost *:80>
DocumentRoot "/data/www"
ServerName www.test.com
Serveralias www.mydiscuz.com
Serveralias www.others.com
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
<ifmodule mod_rewrite.c>
Rewriteengine on
Rewritecond%{http_host} ^www.mydiscuz.com$ [OR]
Rewritecond%{http_host} ^www.others.com$
Rewriterule ^/(. *) $ http://www.test.com/$1 [r=301,l]
</IfModule>
<Directory/data/www/important/>
AllowOverride authconfig
AuthName "username"
AuthType Basic
authuserfile/data/.htpasswd
Require Valid-user
</Directory>
</VirtualHost>
Description
Using the Apache Rotatelogs tool,-l specifies the absolute path to be stored,%y%m%d (YYYYMMDD), 86,400 seconds is a day, and is cut per day
6. Reload the configuration file after checking it correctly:
[Email protected] logs]# apachectl-t
Syntax OK
[Email protected] logs]# Apachectl Graceful
7. Visit our website to produce a log file of the specified cut format:
[[email protected] logs]# ls
Access_log Httpd.pid
Dummy-host.example.com-access_log Test.com-access_20170111_log
Dummy-host.example.com-error_log Test.com-error_log
Error_log
Lamp Build 9:apache Log Cutting