2.2 Apache配置靜態緩存

  CustomLog "|/usr/local/apache2/bin/rotatelogs -l    /usr/local/apache2/logs/custom_%Y%m%d.log 86400"   combined  env=!image-requestjavascript

  <IfModule mod_expires.c>css

    ExpiresActive onhtml

    ExpiresByType image/gif  "access plus 1 days"java

    ExpiresByType image/jpeg "access plus 24 hours"apache

    ExpiresByType image/png "access plus 24 hours"緩存

    ExpiresByType text/css "now plus 2 hour"app

    ExpiresByType application/x-javascript "now plus 2 hours"curl

    ExpiresByType application/javascript "now plus 2 hours"url

    ExpiresByType application/x-shockwave-flash "now plus 2 hours"spa

    ExpiresDefault "now plus 0 min"

</IfModule>

或者使用mod_headers模塊實現

<ifmodule mod_headers.c> 

# htm,html,txt類的文件緩存一個小時 

<filesmatch "\.(html|htm|txt)$"> 

header set cache-control "max-age=3600" 

</filesmatch> 

# css, js, swf類的文件緩存一個星期 

<filesmatch "\.(css|js|swf)$"> 

header set cache-control "max-age=604800" 

</filesmatch> 

# jpg,gif,jpeg,png,ico,flv,pdf等文件緩存一年 

<filesmatch "\.(ico|gif|jpg|jpeg|png|flv|pdf)$"> 

header set cache-control "max-age=29030400" 

</filesmatch> 

</ifmodule> 

# curl -x127.0.0.1:80 "http://www.test.com/static/image/common/logo.png" –I  //快速查看靜態緩存時間

相關文章
相關標籤/搜索