您的位置:首页 > 运维架构 > 网站架构

PHP网站提速 篇二

2016-05-19 10:30 453 查看
Apache配置 mod_expires

让浏览器缓存CSS、JS、图片、静态文件等是很重要的事情,这样可以减轻服务器的压力,省的浏览器经常要去服务端下载这些静态文件。下面看看配置方法吧。

1.开启apache扩展模块mod_expires.so,在apache的配置文件中加入下面一行代码。

LoadModule expires_module modules/mod_expires.so

2.配置缓存,在apache配置文件中加入下面一段代码

<IfModule expires_module>

#打开缓存

ExpiresActive
on

#css文件缓存7200000/3600/24=83天

ExpiresByType
text/css A7200000

#js文件缓存7200000/3600/24=83天

ExpiresByType
application/x-javascript A7200000

ExpiresByType
application/javascript A7200000

#html文件缓存7200000/3600/24=83天

ExpiresByType
text/html A7200000

#图片文件缓存7200000/3600/24=83天

ExpiresByType
image/jpeg A7200000

ExpiresByType
image/gif A7200000

ExpiresByType
image/png A7200000

ExpiresByType
image/x-icon A7200000

</IfModule>

3.测试

访问有图片,css,js,html的文件
http://localhost:8080/test/test.html
用firebug可以看到响应头信息包含

Expires
Tue, 13 Sep 2011 15:41:09 GMT
Cache-Control
max-age=7200000
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: