42 lines
1.3 KiB
Nginx Configuration File
42 lines
1.3 KiB
Nginx Configuration File
server {
|
||
listen 80;
|
||
server_name _;
|
||
|
||
# 管理后台前端构建产物(dist 挂载到 /usr/share/nginx/html)
|
||
root /usr/share/nginx/html;
|
||
index index.html;
|
||
|
||
# 与后端 multer 50MB 上传限制对齐,避免 /api 上传被 nginx 413 拦截
|
||
client_max_body_size 50m;
|
||
gzip on;
|
||
gzip_types text/plain text/css application/json application/javascript image/svg+xml;
|
||
|
||
# 带内容指纹的构建资源:长缓存(正则含 {},必须加引号避免被当作块定界符)
|
||
location ~* "\.[0-9a-f]{8}\.(js|css|png|jpg|jpeg|gif|webp|svg|woff2?)$" {
|
||
expires 365d;
|
||
add_header Cache-Control "public, immutable";
|
||
try_files $uri =404;
|
||
}
|
||
|
||
# 素材库静态文件:backend 上传目录挂载在 dist/uploads,前端直接静态直出
|
||
location /uploads/ {
|
||
expires 7d;
|
||
try_files $uri =404;
|
||
}
|
||
|
||
# SPA history 回退
|
||
location / {
|
||
try_files $uri $uri/ /index.html;
|
||
}
|
||
|
||
# API 反代到 backend 容器(compose 网络内服务名解析)
|
||
location /api/ {
|
||
proxy_pass http://backend:8000;
|
||
proxy_http_version 1.1;
|
||
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;
|
||
}
|
||
}
|