Static file Caching
The static cache is cached under the client, which can set the cache file type and cache time, and increase the speed of client access to the site.
Syntax format
Expiresbytype type/encoding "<base> [plus] <num><type>"
Configure static caching
1. Module Solution Annotation
Vim/apache2/conf/httpd.confloadmodule Expires_module modules/mod_expires.so
2, in the main configuration file editing, it is a global configuration.
vim/apache2/conf/httpd.conf<ifmodule mod_expires.c>#turn on use expiresexpiresactive on#specify GIF file to save 1 days image trigger source/typeExpiresbytype Image/gif"Access plus 1 days" #specify a JPEG file to save for 24 hoursExpiresbytype Image/jpeg"Access plus hours" #Specify a PNG file for 24-hour storageExpiresbytype Image/png"Access plus hours" #Specify a CSS file to save for 2 hoursExpiresbytype Test/css"Now plus 2 hour" #specifies that JavaScript files are saved for 2 hoursExpiresbytype Application/x-javascript"Now plus 2 hours" #specifies that the Flash file is saved for 2 hoursExpiresbytype Application/x-shockwave-flash"Now plus 2 hours" #processing the above files save 0 seconds (do not save)ExpiresDefault"Now plus 0 min"</IfModule>
Master configuration file
3. Load configuration file
/usr/local/apache2/bin/apachectl Graceful
Testing the static cache
1. Firefox test
Firefox-->f12--> network-->304 file--Message header----Response header-->cache-control:max-age=86400 (cache time)
2, the Linux system through the Curl test load is the picture needs to add-I
Curl-x192.168.1.107:80 ' Http://192.168.1.107/static/image/common/logo.png '-I.
http/1.1 200 Okdate:tue, Jan 2018 14:44:10 Gmtserver:apache /2.4.27 (Unix) php/5.3.22last -modified:tue, 2016 03:08:36 Gmtetag: " 1149-5341ab0597500 " accept -ranges:bytescontent -length:4425 cache -control:max-age=86400expires:wed, Jan 2018 14:44:10 gmtcontent -type:image/ png Note: 304 called local cache file Note: Curl 200 does not display 304< Span style= "COLOR: #000000" > note: Max -age=86400 cache time Note: expires:wed, Jan 2018 14:44:10 GMT Expiration Time
Test Results
Apache Static Cache configuration