One access log does not log static file access information
Most of the elements of the site for static files, tablets, CSS, JS, etc., record these access information on our operation is not much significance, if a site access is very large, then a day can reach a few gigabytes. affect the productivity of our disks, then we can configure the virtual host limit to log this information.
Change the virtual host configuration file to the following:
<VirtualHost *:80> DocumentRoot "/data/wwwroot/www.123.com" ServerName www.123.com ServerAlias 123.com 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/123.com-access_log" combined env=!img</VirtualHost>
Reload config file-T, graceful
Mkdir/data/wwwroot/www.123.com/images//Create a directory and upload a picture in this directory
Curl-x127.0.0.1:80-i 123.com/images/123.jpg
Curl-x127.0.0.1:80-i 123.com/345..php
We visit a picture and a PHP page respectively, and then Tail/usr/local/apache2.4/logs/123.com-access_log view the log, we will find that only the information that accesses 345.php is recorded, and no information is recorded to access the image. The statement that directly works here is env=!img one of them! The meaning of the inversion means that the request, except for our definition, is recorded.
Two access log cutting
Logs have been recorded one day will be full disk, and a single log file is not conducive to our location failure, it is necessary to let it automatically cut, and delete old log files
Change the virtual host configuration file to the following:
<VirtualHost *:80> DocumentRoot "/data/wwwroot/www.123.com" ServerName www.123.com ServerAlias 123.com 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 "|/usr/local/apache2.4/bin/rotatelogs -l logs/123.com-access_%Y%m%d.log 86400" combined env=!img</VirtualHost>
Reload config file-T, graceful
Ls/usr/local/apache2.4/logs
Here we find a log file with a date, which is the result of our configuration on the access log cut, where Rotatelos is the httpd of the log cutting tool, it will be the access log in accordance with our defined format for cutting, where 86400 units is the second, equivalent to one day.
Three configuration static element access expiration time
When a browser accesses a picture of a Web site, it caches the static files on the local computer so that it doesn't have to be downloaded remotely the next time you visit. But how long can it be cached, if the picture on the server changes, then the new image should be accessed. This involves the problem of static file cache duration, also known as cache expiration time. This time we can configure in the virtual host configuration file.
We added the following configuration module under the Access log configuration statement
<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>
Note that this configuration requires expires_module, and it needs to be turned on in the httpd configuration file. That is, search for expires_module in/usr/lcoal/apache2.4/conf/httpd.conf, delete the previous # number
Curl test, see Cache-control:max-age
Linux Learning Summary (35) Lamp's access log configuration