squid+apache缓存优化补充
2014-10-14 14:29
627 查看
在上篇介绍过使用apache的mod_expires优化缓存,还可以使用mod_headers,控制和修改http的请求头和应答头。
我们可以通过mod_headers来实现max_age的控制。
例如:
<IfModule mod_headers.c>
# 将内容保存一天
<FilesMatch "\.(flv|gif|ico|jpeg)$">
Header set Cache-Control "max-age=86400"
</FilesMatch>
# 将内容保存一天
<FilesMatch "\.(pdf|swf|js|css)$">
Header set Cache-Control "max-age=86400"
</FilesMatch>
# 将内容保存一天
<FilesMatch "\.(htm|html|shtml)$">
Header set Cache-Control "max-age=86400"
</FilesMatch>
</IfModule>
mod_expires 和 mod_headers 只需要其中一种就可以了。
这样我们在访问相关资源的时候,在相应头中会看到Cache-control: max-age=86400,表明cache的时间是一天,使浏览器能够将这个HTTP响应的内容写入临时目录
做cache。当用户第二次请求被缓存的资源时,浏览器将直接给出响应,不再从服务器请求,直到cache过期。
我们可以通过mod_headers来实现max_age的控制。
例如:
<IfModule mod_headers.c>
# 将内容保存一天
<FilesMatch "\.(flv|gif|ico|jpeg)$">
Header set Cache-Control "max-age=86400"
</FilesMatch>
# 将内容保存一天
<FilesMatch "\.(pdf|swf|js|css)$">
Header set Cache-Control "max-age=86400"
</FilesMatch>
# 将内容保存一天
<FilesMatch "\.(htm|html|shtml)$">
Header set Cache-Control "max-age=86400"
</FilesMatch>
</IfModule>
mod_expires 和 mod_headers 只需要其中一种就可以了。
这样我们在访问相关资源的时候,在相应头中会看到Cache-control: max-age=86400,表明cache的时间是一天,使浏览器能够将这个HTTP响应的内容写入临时目录
做cache。当用户第二次请求被缓存的资源时,浏览器将直接给出响应,不再从服务器请求,直到cache过期。
相关文章推荐
- 谈谈varnish,squid,apache,nginx缓存的对比
- 谈谈varnish,squid,apache,nginx缓存的对比
- varnish、squid、apache、nginx缓存的对比
- Apache网页优化----压缩、缓存
- squid(双向转发+缓存)+apache(双向转发)+web服务器配置详细
- apache的优化-日志轮询、错误页面重定向、压缩功能deflate、客户端缓存expire 推荐
- varnish、squid、apache、nginx缓存的对比
- 谈谈varnish、squid、apache、nginx缓存的对比
- varnish,squid,apache,nginx缓存的对比
- varnish+nging与squid+apache缓存
- squid+apache实现缓存加速
- squid+apache实现缓存加速
- 谈谈varnish,squid,apache,nginx缓存的对比
- 谈谈varnish,squid,apache,nginx缓存的对比
- CDN网络(二)之配置和优化CDN核心缓存软件--squid
- Linux服务器内核参数优化(适合Apache,Nginx,Squid等多种web应用)
- varnish、squid、apache、nginx缓存的对比
- 谈谈varnish,squid,apache,nginx缓存的对比
- 谈谈varnish,squid,apache,nginx缓存的对比
- Squid2.6、Apache2.2优化