fix: nginx添加CORS头解决前端白屏问题

前端构建产物中的script/link标签带有crossorigin属性,
浏览器加载这些资源时会进行CORS检查。
补充Access-Control-Allow-Origin响应头以支持跨域资源加载。
This commit is contained in:
hiderfong
2026-04-25 11:04:27 +08:00
parent e7c7f92b69
commit 9590603621
+2 -1
View File
@@ -33,9 +33,10 @@ server {
proxy_pass http://backend:8000/health; proxy_pass http://backend:8000/health;
} }
# Cache static assets # Cache static assets + CORS for crossorigin attribute
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 30d; expires 30d;
add_header Cache-Control "public, immutable"; add_header Cache-Control "public, immutable";
add_header Access-Control-Allow-Origin * always;
} }
} }