2.2 Apache配置静态缓存

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

  <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>

或者使用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  //快速查看静态缓存时间


你可能感兴趣的:(2.2 Apache配置静态缓存)