lamp设置静态缓存
对于变化不大的内容,如图片之类的。可以设置静态的缓存,那么当客户访问时可以节省带宽减少服务器负担。根据在服务器端设置缓存文件保存时间,客户的浏览器就会根据这个缓存时间保存静态文件配置在对应的虚拟机文件中
1
2
3
4
5
6
7
8
9
10
11
<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>
上面的配置使用了 expires模块设置缓存
缓存时间分 day、hours、min 可以根据自己的需要调整缓存时间或者增加缓存文件类型
测试结果 ,在论坛上拷贝一个图片的地址。使用curl指令
1
2
3
4
5
6
7
8
9
10
11
12
curl -x127.0.0.1:80 www.123.com/data/attachment/forum/201603/29/192652k1j7mspx4dg7dczf.png -I
HTTP/1.1 200 OK
Date: Tue, 29 Mar 2016 13:07:25 GMT
Server: Apache/2.2.31 (Unix) PHP/5.4.45
Last-Modified: Tue, 29 Mar 2016 11:26:52 GMT
ETag: "216b9-4d7d-52f2e4e53244f"
Accept-Ranges: bytes
Content-Length: 19837
Cache-Control: max-age=86400
Expires: Wed, 30 Mar 2016 13:07:25 GMT
Content-Type: image/png
max-age=86400单位是秒 刚好是1天时间24小时。
页:
[1]