# 在开发过程中,可以强制刷新页面
# Chrome/Firefox: Ctrl+F5 或 Shift+F5
# 或者使用无痕模式测试
在Nginx配置文件中添加以下内容:
location / {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires 0;
}
# 对于特定文件类型
location ~* \.(html|htm|js|css)$ {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires 0;
}
sudo nginx -t # 测试配置是否正确
sudo systemctl reload nginx # 重新加载配置
# 或 sudo service nginx reload
为静态资源添加版本号或哈希值,强制浏览器获取新版本:
<link rel="stylesheet" href="styles.css?v=1.0.1">
<script src="app.js?hash=abc123"></script>
如果需要禁用ETag:
etag off;
对于开发环境,可以使用更激进的缓存禁用方式:
server {
# ...
sendfile off; # 禁用sendfile以支持文件修改检测
location / {
if_modified_since off;
add_header Last-Modified "";
etag off;
# 其他禁用缓存头
}
}
使用curl检查响应头:
curl -I http://yourdomain.com/yourpage.html
检查Cache-Control
、Expires
等头部信息
使用浏览器开发者工具查看网络请求,确认响应头是否正确
如果问题仍然存在,请提供具体的Nginx配置和访问的URL模式,我可以提供更针对性的解决方案。