深圳网站建设哪家好?深圳做网站就找深圳乐道网络科技有限公司,乐道网络科技-专业的网站建设公司、网站建设工作室

News新闻

业界新闻动态、技术前沿
Who are we?

您的位置:首页      电脑知识      apache 设置expires和max-age缓存

apache 设置expires和max-age缓存

今天把game的一些组件设置了expire,发现了一个问题,对于同一个操作对象,ExpiresByType比ExpiresDefault优先级高.当expires和max-age同时存在时,max-age的优先级会高于expires.
当你不知道某个文件的MIME类型时,你可以通过浏览器去看httpwatch去看MIME类型.
如果要对某个目录里的某个文件设置Expires头,可以用<filesmatch "正则"></filematch>来匹配.
设置缓存也可以通过mod_headers模块修改cache-control来实现.
header set cache-control "max-age="3600".
mod_expires 实例:
<Directory /opt>
  ExpiresActive On
  ExpiresDefault "accesss plus 3600 seconds"   如果是1秒,后面也是seconds
  ExpiresByType application/octet-stream "accesss plus 1 months"  这是对特殊文件类型bin缓存1个月
  <FilesMatch ^data.swf$> 针对opt目录下data.swf设置Expire值
   ExpiresActive On
   ExpiresDefault "accesss plus 60 seconds"
  </FilesMatch>
</Directory>
mod_headers实例
<Directory /opt>
  header set cache-control "max-age=3600"
  <FilesMatch ^data.swf$>
  header set cache-control "max-age=60"
  </FilesMatch>
</Directory>