一、语法
bash
# 默认 expires off;
# Context: http,server,location
# epoch代表具体时间,max代表10年
expires [modified] time;
expires epoch|max|off;
二、观察浏览器缓存
- 禁用缓存的时候每次访问的http状态码都是[[HTTP状态码^200|200]]
- 开启缓存后,对于已经访问过的页面,再次访问的时候http状态码都是[[HTTP状态码#^66bfc7|304]]
三、理解nginx缓存
1.开启nginx缓存模块
bash
# lj.conf
location / {
expires 24h; #24小时内不再从服务器请求资源,因为资源缓存在本地
}
2.响应头信息
3.特点
- 加速浏览
- ==缺点是时效性降低==
4.注意事项
对时效性要求较高的站点不要开启缓存