响应码为200为什么还是有缓存?
我在虚拟机上练习nginx负载均衡,使用默认的策略,指向两个tomcat
我用chrome浏览器访问
情况1. 在无痕窗口下可以看到轮流在两个tomcat之间切换
情况2. 在普通窗口下,却一直是同一个tomcat(快速多次刷新才偶尔有切换)
我发现响应码多为304,于是使用ctrl+f5刷新,响应码变为200(不是200 from disk cache),但是效果还是一样
其他情况. url加上随机参数,或者使用IE8访问,可以在两个tomcat之间切换
情况2是仍然有缓存吗?还是别的因素?
nginx配置
upstream myserver{
server 127.0.0.1:8080
server 127.0.0.1:8081
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://myserver;
root html;
index index.html index.htm;
}
}
普通窗口ctrl+f5的headers
#response headers
Accept-Ranges: bytes
Connection: keep-alive
Content-Length: 13
Content-Type: text/html
Date: Fri, 16 Apr 2021 16:18:19 GMT
ETag: W/"13-1618502968000"
Last-Modified: Thu, 15 Apr 2021 16:09:28 GMT
Server: nginx/1.19.10
#request headers
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cache-Control: no-cache
Connection: keep-alive
Host: 192.168.116.128
Pragma: no-cache
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
无痕窗口的headers
#response headers
Accept-Ranges: bytes
Connection: keep-alive
Content-Length: 13
Content-Type: text/html
Date: Fri, 16 Apr 2021 16:19:53 GMT
ETag: W/"13-1618502946000"
Last-Modified: Thu, 15 Apr 2021 16:09:06 GMT
Server: nginx/1.19.10
#request headers
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cache-Control: max-age=0
Connection: keep-alive
Host: 192.168.116.128
If-Modified-Since: Thu, 15 Apr 2021 16:09:28 GMT
If-None-Match: W/"13-1618502968000"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你请求的地址是静态资源么?
这三行是http控制缓存的头.
不清楚是你的nginx还是tomcat加的.
如果响应If-Modified-Since, Last-Modified两个头匹配, 就会使用缓存
解决
把tomcat的缓存给禁了.