Access logs do not record static files; access log cuts; expiration time of elements such as static pictures
Expansion
Apache logging agent IP and real client IP http://www.lishiming.net/thread-960-1-1.html
Apache records only the log http://www.lishiming.net/thread-981-1-1.html of the specified URI
Apache logs the domain name http://www.lishiming.net/thread-1037-1-1.html requested by the client
Apache log slicing problem http://www.lishiming.net/thread-566-1-1.html
11.22 access logs do not record static files
Most of the elements of the site are static files such as pictures, css, js, etc. These elements can be recorded without recording.
1. Edit virtual machine configuration files, add access logs, do not record pictures, static files and other rules
[root@hao-01 ~] # vim / usr/local/apache2.4/conf/extra/httpd-vhosts.conf
Add content (filter out image access for access logs)
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 environs
two。 Detect virtual machine configuration files for errors
[root@hao-01] # / usr/local/apache2.4/bin/apachectl-t
3. Start apache2.4/httpd
[root@hao-01 apache2.4] # / usr/local/apache2.4/bin/apachectl start
4. Reload the configuration file (service will not be restarted)
[root@hao-01 ~] # / usr/local/apache2.4/bin/apachectl graceful
5. Go to the directory of 111 website
[root@hao-01 ~] # cd / data/wwwroot/111.com
6. Upload a picture from window to the current directory
[root@hao-01 111.com] # rz
7. Curl command to access the image name and address under 111.com (200OK)
[root@hao-01 111.com] # curl-x127.0.0.1 111.com/clipboard.png 80 111.com/clipboard.png-I
8. Constantly refresh access to 111.com/clipboard.png (upload image address) in windows browser
9. If you check the access log, you can't see the access log in .png format, which is filtered out and not recorded.
[root@hao-01 111.com] # tail / usr/local/apache2.4/logs/111.com-access_log
11.23 access Log cutting
The log has been recorded all the time, and one day the whole disk will be full.
So it is necessary to let it automatically cut and delete the old log files.
1. Edit the virtual machine configuration file to specify the log as an access log on a daily date
[root@hao-01 ~] # vim / usr/local/apache2.4/conf/extra/httpd-vhosts.conf
The access log is added to change the following rules (set the log to be cut into multiple files)
CustomLog "| / usr/local/apache2.4/bin/rotatelogs-l logs/111.com-access_%Y%m%d.log 86400" combined environs
two。 Detect virtual machine configuration files for errors
[root@hao-01] # / usr/local/apache2.4/bin/apachectl-t
3. Reload the configuration file (service will not be restarted)
[root@hao-01 ~] # / usr/local/apache2.4/bin/apachectl graceful
4. Access the 123.php file under the 111.com website with the curl command
[root@hao-01 ~] # curl-x127.0.0.1 111.com/123.php
5. List all logs under the apache access log directory (you can see the log named by date)
[root@hao-01 ~] # ls / usr/local/apache2.4/logs/
6. View the contents of the log named after the date you just visited (just visited 123.php)
[root@hao-01 ~] # cat / usr/local/apache2.4/logs/123.php/111.com-access_20170801.log
11.24 static element expiration time
1. Modify the virtual host profile to define the expiration time of elements such as static pictures
Insert content (definition of expiration time of elements such as static pictures)
ExpiresActive on
ExpiresByType p_w_picpath/gif "access plus 1 days"
ExpiresByType p_w_picpath/jpeg "access plus 24 hours"
ExpiresByType p_w_picpath/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"
two。 Detect virtual machine configuration files for errors
[root@hao-01] # / usr/local/apache2.4/bin/apachectl-t
3. Reload the configuration file (service will not be restarted)
[root@hao-01 ~] # / usr/local/apache2.4/bin/apachectl graceful
4. Edit the apache master configuration to open the line containing expires (delete the # sign before the line)
5. Search for whether the apacheexpire module is open
[root@hao-01 ~] # / usr/local/apache2.4/bin/apachectl-M | grep expire
6. Use the curl command to access the static picture clipboard.php in the 111.com directory:
(if the current access time and cache static expiration time are displayed, the expiration will be cleaned up)
[root@hao-01] # curl-x127.0.0.1 111.com/clipboard.png-I