Apache 静态缓存配置

静态文件缓存javascript

  静态缓存在客户端下进行缓存,能够设置缓存文件类型与缓存时间,提高客户端访问站点速度。css

 

语法格式java

ExpiresByType type/encoding “<base> [plus] <num><type>”

 

配置静态缓存apache

一、模块解注释
vim /apache2/conf/httpd.conf

LoadModule expires_module modules/mod_expires.so

二、主配置文件内编辑,它是一个全局配置。vim

vim /apache2/conf/httpd.conf <IfModule mod_expires.c>
   # 开启使用expires
 ExpiresActive on # 指定gif 文件保存1天 image触发源/类型
   ExpiresByType image/gif "access plus 1 days"
   # 指定jpeg 文件保存24小时
   ExpiresByType image/jpeg "access plus 24 hours"
   # 指定png 文件保存24小时
   ExpiresByType image/png "access plus 24 hours"
   # 指定css 文件保存2小时
   ExpiresByType test/css "now plus 2 hour"
   # 指定javascript 文件保存2小时
   ExpiresByType application/x-javascript "now plus 2 hours"
   # 指定flash 文件保存2小时
   ExpiresByType application/x-shockwave-flash "now plus 2 hours"
   # 处理上述文件 其余都保存0秒(不保存)
   ExpiresDefault "now plus 0 min"
</IfModule>
主配置文件

三、加载配置文件浏览器

/usr/local/apache2/bin/apachectl graceful

 

测试静态缓存缓存

一、火狐浏览器测试网络

火狐浏览器-->F12-->网络-->304文件-->消息头-->响应头-->Cache-Control:max-age=86400(缓存时间)

二、Linux系统下经过curl 测试 加载的是图片 须要加 -Iapp

curl -x192.168.1.107:80 'http://192.168.1.107/static/image/common/logo.png' -I
HTTP/1.1 200 OK Date: Tue, 23 Jan 2018 14:44:10 GMT Server: Apache/2.4.27 (Unix) PHP/5.3.22 Last-Modified: Tue, 31 May 2016 03:08:36 GMT ETag: "1149-5341ab0597500" Accept-Ranges: bytes Content-Length: 4425 Cache-Control: max-age=86400 Expires: Wed, 24 Jan 2018 14:44:10 GMT Content-Type: image/png 注:304 调用了本地的缓存文件 注:curl 200 不会显示 304 注:max-age=86400 缓存时间 注:Expires: Wed, 24 Jan 2018 14:44:10 GMT 过时时间
测试结果
相关文章
相关标签/搜索