[feat]增加nginx不缓存index.html配置,搭配前端版本自动升级功能使用(不加此配置可能会导致用户刷新后还是旧版本)

This commit is contained in:
周继风
2024-06-25 10:17:36 +08:00
parent 0529c2747a
commit 38ad2db7a7
2 changed files with 8 additions and 0 deletions

View File

@@ -7,6 +7,10 @@ server {
index index.html index.htm; index index.html index.htm;
root /usr/share/nginx/html; root /usr/share/nginx/html;
try_files $uri $uri/ /index.html; try_files $uri $uri/ /index.html;
# 禁止缓存html文件,避免前端页面不及时更新,需要用户手动刷新的情况
if ($request_uri ~* "^/$|^/index.html|^/index.htm") {
add_header Cache-Control "no-store";
}
} }
location ~ ^/api/ { location ~ ^/api/ {

View File

@@ -11,6 +11,10 @@ server {
real_ip_header X-Forwarded-For; real_ip_header X-Forwarded-For;
root /usr/share/nginx/html; root /usr/share/nginx/html;
index index.html index.php index.htm; index index.html index.php index.htm;
# 禁止缓存html文件,避免前端页面不及时更新,需要用户手动刷新的情况
if ($request_uri ~* "^/$|^/index.html|^/index.htm") {
add_header Cache-Control "no-store";
}
} }
location /api/ { location /api/ {