目录
一、添加浏览器缓存配置语法(即添加Cache-Control、Expires头信息)
- 一、添加浏览器缓存配置语法(即添加Cache-Control、Expires头信息)
- 二、添加浏览器缓存的配置演示
- 1、配置nginx访问html页面的路径
- 2、编辑nginx.conf配置文件
- 3、启动nginx服务并检查配置文件
- 4、浏览器第一次请求testExpires.html页面
- 5、浏览器第二次请求testExpires.html页面
- Syntax:expires [modified] time; 表示缓存的有效期;
- Default:expires off; 表示默认关闭
- Context:http,server,location; 表示需要在http块、或server块、或location块中
- 创建testExpires.html页面,上传到/opt/app/html目录下
expires hello world!
-
编辑nginx.conf配置文件,在http块的server块的location块中配置访问/opt/app/html目录下的testExpires.html页面,如下内容
location ~ .*\.(html|htm)$ { expires 24h; root /opt/app/html; }
-
启动nginx服务
[root@localhost nginx]# systemctl start nginx.service
-
检查配置修改的配置文件是否正确,返回successful表示配置文件修改无错
[root@localhost nginx]# nginx -t -c /etc/nginx/nginx.conf nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
-
重新加载配置文件
[root@localhost /]# systemctl reload nginx
-
浏览器第一次请求的状态、请求头信息,服务端返回的头信息如下图:
-
浏览器第二次请求的状态、请求头信息,服务端返回的头信息如下图: