50 lines
1.8 KiB
Nginx Configuration File
50 lines
1.8 KiB
Nginx Configuration File
server {
|
|
listen 80;
|
|
server_name localhost;
|
|
client_max_body_size 200m;
|
|
client_body_timeout 300s;
|
|
send_timeout 300s;
|
|
resolver 127.0.0.11 valid=30s ipv6=off;
|
|
resolver_timeout 5s;
|
|
|
|
# 静态资源服务
|
|
location / {
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
# Vite 构建产物(/assets/ 下带 hash 文件):内容寻址,文件名一变即换新缓存,可放心长期 immutable 缓存。
|
|
location /assets/ {
|
|
root /usr/share/nginx/html;
|
|
add_header Cache-Control "public, max-age=31536000, immutable";
|
|
}
|
|
|
|
# index.html 必须始终重新校验(no-cache):避免浏览器/网关缓存旧版 HTML,引用部署后已删除的旧 hash 产物,
|
|
# 导致登录后懒加载 chunk 404,报 "Failed to fetch dynamically imported module"。
|
|
location = /index.html {
|
|
root /usr/share/nginx/html;
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
}
|
|
|
|
# API 代理到后端
|
|
location /api/ {
|
|
# 通过 Docker 内置 DNS 动态解析后端服务,避免后端容器重建后
|
|
# Nginx 继续使用启动时缓存的旧 IP 而出现 502。
|
|
set $backend_upstream hxops-backend:5000;
|
|
# 变量形式下不要附带 URI,保留原始 /api/... 路径透传给后端。
|
|
proxy_pass http://$backend_upstream;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
# SSE 支持
|
|
proxy_buffering off;
|
|
proxy_cache off;
|
|
proxy_read_timeout 300s;
|
|
proxy_connect_timeout 75s;
|
|
proxy_send_timeout 300s;
|
|
}
|
|
}
|