11.22 The access log does not record static files or files of the specified type
Most of the elements of the website are static files, such as pictures, css, js, etc. These elements do not need to be recorded.
Change the virtual host configuration file to the following:
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/111.com"
ServerName 111.com
ServerAlias www.example.com2111.com.cn
ErrorLog "logs/111.com-error_log"
SetEnvIf Request_URI ".*\.gif$" img
SetEnvIf Request_URI ".*\.jpg$" img
SetEnvIf Request_URI ".*\.png$" img
SetEnvIf Request_URI ".*\.bmp$" img
SetEnvIf Request_URI ".*\.swf$" img
SetEnvIf Request_URI ".*\.js$" img
SetEnvIf Request_URI ".*\.css$" img
CustomLog "logs/111.com-access_log" combined env=!img
</VirtualHost>
reload config file -t, graceful
curl -x127.0.0.1:80 -I 111.com/abc.jpg1 -I
tail
127.0.0.1 - - [24/Dec/2017:22:30:01 +0800] "HEAD HTTP://111.com/abc.jpg1 HTTP/1.1" 404 - "-" "curl/7.29.0"
tail /usr/local/apache2.4/logs/111.com-access_log
If you need to display image information, you can delete env=!img, and img can also be changed to any other character.
11.23 Access log cutting
The log keeps recording and will fill up the entire disk one day, so it is necessary to let it automatically cut and delete the old log files
Change the virtual host configuration file to the following:
Just modify CustomLog
<VirtualHost *:80>
CustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/111.com-access_%Y%m%d.log 86400" combined env=!img
</VirtualHost>
reload config file -t, graceful
ls /usr/local/apache2.4/logs
[root@localhost 111.com]# ls /usr/local/apache2.4/logs
111.com-access_20171225.log 111.com-error_log abc.com-error_log error_log
111.com-access_log abc.com-access_log access_log httpd.pid
[root@localhost 111.com]# ls /usr/local/apache2.4/logs/111.com-access_20171225.log
/usr/local/apache2.4/logs/111.com-access_20171225.log
[root@localhost 111.com]# cat !$
cat /usr/local/apache2.4/logs/111.com-access_20171225.log
127.0.0.1 - - [25/Dec/2017:12:08:54 +0800] "HEAD HTTP://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0"
11.24 Static Element Expiration Time
When the browser accesses the pictures of the website, it will cache the static files in the local computer, so that the next time you visit, you don't have to download it remotely.
Add configuration
Add a line above the error
<IfModule mod_expires.c>
ExpiresActive on //打开该功能的开关
ExpiresByType image/gif "access plus 1 days"
ExpiresByType image/jpeg "access plus 24 hours"
ExpiresByType image/png "access plus 24 hours"
ExpiresByType text/css "now plus 2 hour"
ExpiresByType application/x-javascript "now plus 2 hours"
ExpiresByType application/javascript "now plus 2 hours"
ExpiresByType application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0 min"
</IfModule>
-t graceful
/usr/local/apache2.4/bin/apachectl -M |grep expires
vim /usr/local/apache2.4/conf/httpd.conf
Need to uncomment expires_module
curl test, see cache-control: max-age
expand
apache logging proxy IP as well as real client IP http://ask.apelearn.com/question/960
apache only logs the specified URI http://ask.apelearn.com/question/981
apache logging client request domain name http://ask.apelearn.com/question/1037
apache log cutting problem http://ask.apelearn.com/question/566