chore: 将验证文件改为宿主机挂载热加载

Made-with: Cursor
This commit is contained in:
whm
2026-03-18 10:53:35 +08:00
parent 81cd9dce75
commit 31b1f2bb4c
4 changed files with 20 additions and 1 deletions

View File

@@ -32,6 +32,9 @@ services:
REGISTRY_MIRROR: ${REGISTRY_MIRROR:-}
image: yh_web-web:latest
container_name: yh_web
volumes:
# 仅挂载验证文件目录,便于热更新;前台静态站点仍由镜像内 dist 提供
- ./verify-root:/verify-root:ro
networks:
- yh_net
# 不暴露宿主机端口,仅由 nginx 容器反代

View File

@@ -56,6 +56,8 @@ sudo systemctl reload nginx
**/api/health 或 /admin/ 返回 404 时**:在服务器执行 `ss -tlnp | grep 443`,看 443 是宿主机 nginx 还是 docker。若是宿主机 nginx要么停用该站点配置让 compose 独占 443方式 A要么改为方式 Bcompose 用 8443宿主机反代到 8443
**验证文件热加载**:如果只需要把某些根目录验证文件上线,放到项目根目录的 `verify-root/` 里即可,`web` 容器会把它挂载为 `/verify-root`,并直接从网站根路径提供这些 `.txt/.html/.xml` 文件。修改文件后不需要重建 `web` 镜像,只要文件保存到宿主机上就会立刻生效。
## 4. 新服务器首次安装 Nginx
```bash

View File

@@ -11,6 +11,20 @@ RUN npm run build
ARG REGISTRY_MIRROR=docker.m.daocloud.io/library/
FROM ${REGISTRY_MIRROR}nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
RUN echo 'server { listen 80; root /usr/share/nginx/html; index index.html; location / { try_files $uri $uri/ /index.html; } }' > /etc/nginx/conf.d/default.conf
RUN printf '%s\n' \
'server {' \
' listen 80;' \
' root /usr/share/nginx/html;' \
' index index.html;' \
'' \
' # 根路径下的验证文件走热加载目录,不需要重建镜像' \
' location ~ ^/([A-Za-z0-9._-]+\.(txt|html|xml))$ {' \
' alias /verify-root/$1;' \
' }' \
'' \
' location / {' \
' try_files $uri $uri/ /index.html;' \
' }' \
'}' > /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]