45 lines
1.8 KiB
Plaintext
45 lines
1.8 KiB
Plaintext
|
|
server {
|
|||
|
|
listen 80;
|
|||
|
|
server_name _;
|
|||
|
|
charset utf-8;
|
|||
|
|
|
|||
|
|
# 站点根 = 宿主机 web/ 目录(compose 里 ./web:/usr/share/nginx/html:ro)
|
|||
|
|
# 临时改页面:替换 web/ 下的文件后 docker compose restart web,不用重建镜像
|
|||
|
|
root /usr/share/nginx/html;
|
|||
|
|
index index.html;
|
|||
|
|
|
|||
|
|
# 与后端 multipart 上限(500MB)保持一致,改这里要同步改 config/application.yml
|
|||
|
|
client_max_body_size 500m;
|
|||
|
|
client_body_timeout 300s;
|
|||
|
|
|
|||
|
|
# /api/xxx -> 后端 /xxx(去掉 /api 前缀,与前端构建时的 VITE_API_URL=/api 对应)
|
|||
|
|
# app 是 compose 里的服务名,改了服务名这里要跟着改
|
|||
|
|
location /api/ {
|
|||
|
|
proxy_pass http://app:8080/;
|
|||
|
|
proxy_http_version 1.1;
|
|||
|
|
# 必须保留端口($http_host):后端 getRootDomain 对「无端口的 IP/localhost」会抛
|
|||
|
|
# IllegalStateException,导致登录成功回调 500。改成 $host 就会复现这个坑
|
|||
|
|
proxy_set_header Host $http_host;
|
|||
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|||
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|||
|
|
proxy_set_header Upgrade $http_upgrade;
|
|||
|
|
proxy_set_header Connection "upgrade";
|
|||
|
|
proxy_connect_timeout 60s;
|
|||
|
|
proxy_read_timeout 600s;
|
|||
|
|
proxy_send_timeout 600s;
|
|||
|
|
# 大文件上传不在 nginx 侧缓冲,直接流给后端
|
|||
|
|
proxy_request_buffering off;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# SPA:hash 路由,静态资源找不到时回落 index.html
|
|||
|
|
location / {
|
|||
|
|
try_files $uri $uri/ /index.html;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 构建产物的文件名自带 hash,可以放心缓存;index.html 不在其中,换包后浏览器直接拿到新的
|
|||
|
|
location ~* \.(js|mjs|css|woff2?|ttf|png|jpe?g|gif|svg|ico)$ {
|
|||
|
|
expires 7d;
|
|||
|
|
access_log off;
|
|||
|
|
}
|
|||
|
|
}
|