fix(deploy): web.conf 移到 fuellog-web/ 自己的 build context
NAS 部署时 web 阶段失败: failed to solve: failed to compute cache key: "/deploy/nginx/web.conf": not found 根因:fuellog-web/Dockerfile 的 `COPY deploy/nginx/web.conf` 是相对 build context 的。web Dockerfile 的 context = fuellog-web/,所以它在找 fuellog-web/deploy/nginx/web.conf —— 实际文件在仓库根的 deploy/nginx/web.conf, 出 context 了,build 报错。 修法:把 web.conf 移到 web 自己的 build context 内,放到 fuellog-web/nginx/web.conf。 Dockerfile COPY 改成 `COPY nginx/web.conf`。同时 deploy/docker-compose.dev.yml 的 bind-mount 路径从 ./nginx/web.conf 改成 ../fuellog-web/nginx/web.conf。 deploy/nginx/web.conf 保留为重定向注释占位,deploy/ 目录在 git 里仍是 有效的,避免外部引用突然找不到。 期间顺带:dev compose 之前 `./nginx/web.conf` 路径是相对 deploy/,符合 compose 的"相对 compose 文件找依赖"约定,改成 `../fuellog-web/nginx/web.conf` 也保持一致;prod compose 不动,它只 build 不直接挂文件。 未做(留待后续): - 把 deploy/nginx/web.conf 直接 rm 掉(目前用"重定向注释"占位); PowerShell 没有 mavis-trash,删文件会被拦。后续可改用 .gitkeep + 真删 流程,或干脆用符号链接 - fuellog-web/deploy/ 之类的隔离目录,等真正需要再说
This commit is contained in:
@@ -36,7 +36,7 @@ services:
|
|||||||
# dev 期把本地 build 产物挂到 nginx 静态目录
|
# dev 期把本地 build 产物挂到 nginx 静态目录
|
||||||
# 用法:cd fuellog-web && pnpm build,然后 docker compose restart web
|
# 用法:cd fuellog-web && pnpm build,然后 docker compose restart web
|
||||||
- ../fuellog-web/dist:/usr/share/nginx/html:ro
|
- ../fuellog-web/dist:/usr/share/nginx/html:ro
|
||||||
- ./nginx/web.conf:/etc/nginx/conf.d/web.conf:ro
|
- ../fuellog-web/nginx/web.conf:/etc/nginx/conf.d/web.conf:ro
|
||||||
networks:
|
networks:
|
||||||
- fuellog-net
|
- fuellog-net
|
||||||
|
|
||||||
|
|||||||
+5
-56
@@ -1,56 +1,5 @@
|
|||||||
# FuelLog 前端容器用的 nginx 配置
|
# 已迁移到 ../fuellog-web/nginx/web.conf
|
||||||
# - 提供 /usr/share/nginx/html 静态资源
|
# 这里保留一个空文件占位,deploy/ 目录在 git 里仍是有效的;
|
||||||
# - SPA fallback:所有非 /api 路径都回 /index.html(让 vue-router 接管)
|
# 旧的 docker-compose 引用 (./nginx/web.conf) 如果还有人用,
|
||||||
# - /api/* 反代到后端容器 api:8080
|
# 需要把 volume 行改成 ../fuellog-web/nginx/web.conf。
|
||||||
|
# 推荐:直接用 ../fuellog-web/nginx/web.conf。
|
||||||
upstream fuellog_api {
|
|
||||||
server api:8080;
|
|
||||||
keepalive 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 80 default_server;
|
|
||||||
server_name _;
|
|
||||||
|
|
||||||
# gzip 静态资源
|
|
||||||
gzip on;
|
|
||||||
gzip_types text/plain text/css application/javascript application/json image/svg+xml application/xml;
|
|
||||||
gzip_min_length 1024;
|
|
||||||
|
|
||||||
# 静态资源 + SPA fallback
|
|
||||||
root /usr/share/nginx/html;
|
|
||||||
index index.html;
|
|
||||||
|
|
||||||
# 显式 favicon / manifest / icon
|
|
||||||
location = /favicon.svg { access_log off; expires 30d; }
|
|
||||||
location = /manifest.webmanifest { access_log off; expires 1d; }
|
|
||||||
location ~* ^/pwa-.*\.png$ { access_log off; expires 30d; }
|
|
||||||
|
|
||||||
# 反代 /api 到后端
|
|
||||||
location /api/ {
|
|
||||||
proxy_pass http://fuellog_api;
|
|
||||||
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;
|
|
||||||
proxy_set_header Connection ""; # keep-alive
|
|
||||||
proxy_read_timeout 30s;
|
|
||||||
proxy_send_timeout 30s;
|
|
||||||
}
|
|
||||||
|
|
||||||
# /api/health 这种后端直出,允许直接走
|
|
||||||
location = /health { proxy_pass http://fuellog_api/health; }
|
|
||||||
|
|
||||||
# Hashed 静态资源(js/css/woff2)长缓存
|
|
||||||
location ~* \.(?:js|css|woff2|svg|png|jpg|jpeg|gif|ico)$ {
|
|
||||||
expires 30d;
|
|
||||||
add_header Cache-Control "public, immutable";
|
|
||||||
try_files $uri =404;
|
|
||||||
}
|
|
||||||
|
|
||||||
# SPA fallback
|
|
||||||
location / {
|
|
||||||
try_files $uri $uri/ /index.html;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ FROM nginx:1.27-alpine
|
|||||||
RUN rm /etc/nginx/conf.d/default.conf
|
RUN rm /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
# 我们的反代 + SPA fallback 配置
|
# 我们的反代 + SPA fallback 配置
|
||||||
COPY deploy/nginx/web.conf /etc/nginx/conf.d/web.conf
|
COPY nginx/web.conf /etc/nginx/conf.d/web.conf
|
||||||
|
|
||||||
# 静态产物
|
# 静态产物
|
||||||
COPY --from=builder /src/dist /usr/share/nginx/html
|
COPY --from=builder /src/dist /usr/share/nginx/html
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
# FuelLog 前端容器用的 nginx 配置
|
||||||
|
# - 提供 /usr/share/nginx/html 静态资源
|
||||||
|
# - SPA fallback:所有非 /api 路径都回 /index.html(让 vue-router 接管)
|
||||||
|
# - /api/* 反代到后端容器 api:8080
|
||||||
|
|
||||||
|
upstream fuellog_api {
|
||||||
|
server api:8080;
|
||||||
|
keepalive 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80 default_server;
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
# gzip 静态资源
|
||||||
|
gzip on;
|
||||||
|
gzip_types text/plain text/css application/javascript application/json image/svg+xml application/xml;
|
||||||
|
gzip_min_length 1024;
|
||||||
|
|
||||||
|
# 静态资源 + SPA fallback
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
# 显式 favicon / manifest / icon
|
||||||
|
location = /favicon.svg { access_log off; expires 30d; }
|
||||||
|
location = /manifest.webmanifest { access_log off; expires 1d; }
|
||||||
|
location ~* ^/pwa-.*\.png$ { access_log off; expires 30d; }
|
||||||
|
|
||||||
|
# 反代 /api 到后端
|
||||||
|
location /api/ {
|
||||||
|
proxy_pass http://fuellog_api;
|
||||||
|
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;
|
||||||
|
proxy_set_header Connection ""; # keep-alive
|
||||||
|
proxy_read_timeout 30s;
|
||||||
|
proxy_send_timeout 30s;
|
||||||
|
}
|
||||||
|
|
||||||
|
# /api/health 这种后端直出,允许直接走
|
||||||
|
location = /health { proxy_pass http://fuellog_api/health; }
|
||||||
|
|
||||||
|
# Hashed 静态资源(js/css/woff2)长缓存
|
||||||
|
location ~* \.(?:js|css|woff2|svg|png|jpg|jpeg|gif|ico)$ {
|
||||||
|
expires 30d;
|
||||||
|
add_header Cache-Control "public, immutable";
|
||||||
|
try_files $uri =404;
|
||||||
|
}
|
||||||
|
|
||||||
|
# SPA fallback
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user