Files
toor 7049eb02a8 feat: 增加 Docker 部署(Dockerfile + compose,端口 2229)
用多阶段构建把 Nuxt 静态产物交给 nginx 托管,对外暴露 2229 端口。
nginx 配置覆盖 SPA 路由回退与静态资源缓存策略,构建上下文用 .dockerignore 排除依赖与产物。
2026-10-21 14:38:50 +08:00

50 lines
1.3 KiB
Nginx Configuration File

server {
listen 2229;
server_name _;
root /usr/share/nginx/html;
index index.html;
# 静态资源压缩
# 注意:显式声明 gzip_types 会覆盖内置默认列表,但 text/html 始终会被压缩,无需重复声明
#(重复写 text/html 只会触发 nginx 的 duplicate MIME type 警告)
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/javascript
application/json
application/xml
image/svg+xml;
# 带内容哈希的构建产物可以长期缓存
location /_nuxt/ {
add_header Cache-Control "public, max-age=31536000, immutable";
try_files $uri =404;
}
# Service Worker 每次都要回源校验,否则老用户会被锁在旧版本
location = /sw.js {
add_header Cache-Control "no-cache, no-store, must-revalidate";
try_files $uri =404;
}
# 无扩展名的关联域名文件需要正确的 Content-Type
location /.well-known/ {
default_type application/json;
add_header Cache-Control "public, max-age=3600";
try_files $uri =404;
}
# CSR 应用:未预渲染的路由交给前端路由处理
location / {
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
}