【CentOS 7架構11】,靜態元素過時時間#

shallow丿ovejavascript


配置靜態元素過時時間

  • 瀏覽器訪問網站的圖片時會把靜態的文件緩存在本地電腦裏,這樣下次再訪問時就不用去遠程下載
  • 增長配置 <IfMondule 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" ExpiresByType "now plus 0 min" </IfModule>
  • 須要expires module
  • curl測試,看cache-control:max-age
45         RewriteEngine on
     46         RewriteCond %{HTTP_HOST} !^111.com$
     47         RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L]
     48     </IfModule>
     49     <IfModule mod_expires.c>
     50         ExpiresActive on
     51         ExpiresByType image/gif "access plus 1 days"
     52         ExpiresByType image/jpeg "access plus 24 hours"
     53         ExpiresByType image/png "access plus 24 hours"
     54         ExpiresByType text/css "now plus 24 hours"
     55         ExpiresByType application/x-javascript "now plus 2 hours"
     56         ExpiresByType application/javascript "now plus 2 hours"
     57         ExpiresByType application/x-shockwave-flash "now plus 2 hours"
     58         ExpiresDefault "now plus 0 min"
     59     </IfModule>
     60     ErrorLog "logs/111.com-error_log"
[root@localhost 111.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@localhost 111.com]# /usr/local/apache2.4/bin/apachectl graceful
[root@localhost 111.com]# /usr/local/apache2.4/bin/apachectl -M | grep expires
[root@localhost 111.com]# vi /usr/local/apache2.4/conf/httpd.conf
[root@localhost 111.com]# vi /usr/local/apache2.4/conf/httpd.conf
/expires
    103 #LoadModule sed_module modules/mod_sed.so
    104 #LoadModule deflate_module modules/mod_deflate.so
    105 LoadModule mime_module modules/mod_mime.so
    106 LoadModule log_config_module modules/mod_log_config.so
    107 #LoadModule log_debug_module modules/mod_log_debug.so
    108 #LoadModule logio_module modules/mod_logio.so
    109 LoadModule env_module modules/mod_env.so
    110 #LoadModule expires_module modules/mod_expires.so
    111 LoadModule headers_module modules/mod_headers.so
    112 #LoadModule unique_id_module modules/mod_unique_id.so
    113 LoadModule setenvif_module modules/mod_setenvif.so
    114 LoadModule version_module modules/mod_version.so
    115 #LoadModule remoteip_module modules/mod_remoteip.so
    116 #LoadModule proxy_module modules/mod_proxy.so
    117 #LoadModule proxy_connect_module modules/mod_proxy_connect.so
    118 #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so

將expires模塊打開css

[root@localhost 111.com]# /usr/local/apache2.4/bin/apachectl -M | grep expires
 expires_module (shared)
[root@localhost 111.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@localhost 111.com]# /usr/local/apache2.4/bin/apachectl graceful
[root@localhost 111.com]# curl -x 127.0.0.1:80 111.com/1111.png -I
HTTP/1.1 200 OK
Date: Sat, 04 Nov 2017 15:12:48 GMT
Server: Apache/2.4.29 (Unix) PHP/5.6.30
Last-Modified: Sat, 04 Nov 2017 15:12:48 GMT
ETag: W/"99ad-560d9271dfe00"
Accept-Ranges: bytes
Content-Length: 39341
Cache-Control: max-age=86400
Expires: Sun, 05 Nov 2017 15:12:48 GMT
Content-Type: image/png
相關文章
相關標籤/搜索