From 31b1f2bb4c24a98b04a263f39e1f68e5e1937535 Mon Sep 17 00:00:00 2001 From: whm <973418690@qq.com> Date: Wed, 18 Mar 2026 10:53:35 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=B0=86=E9=AA=8C=E8=AF=81=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=94=B9=E4=B8=BA=E5=AE=BF=E4=B8=BB=E6=9C=BA=E6=8C=82?= =?UTF-8?q?=E8=BD=BD=E7=83=AD=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- docker-compose.yml | 3 +++ nginx/README.md | 2 ++ .../bc406b475509fc295a067baf2eef681a.txt | 0 web/Dockerfile | 16 +++++++++++++++- 4 files changed, 20 insertions(+), 1 deletion(-) rename {web/public => verify-root}/bc406b475509fc295a067baf2eef681a.txt (100%) diff --git a/docker-compose.yml b/docker-compose.yml index 7a6d75d..0af7157 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 容器反代 diff --git a/nginx/README.md b/nginx/README.md index fb144d6..2d21d1f 100644 --- a/nginx/README.md +++ b/nginx/README.md @@ -56,6 +56,8 @@ sudo systemctl reload nginx **/api/health 或 /admin/ 返回 404 时**:在服务器执行 `ss -tlnp | grep 443`,看 443 是宿主机 nginx 还是 docker。若是宿主机 nginx,要么停用该站点配置让 compose 独占 443(方式 A),要么改为方式 B(compose 用 8443,宿主机反代到 8443)。 +**验证文件热加载**:如果只需要把某些根目录验证文件上线,放到项目根目录的 `verify-root/` 里即可,`web` 容器会把它挂载为 `/verify-root`,并直接从网站根路径提供这些 `.txt/.html/.xml` 文件。修改文件后不需要重建 `web` 镜像,只要文件保存到宿主机上就会立刻生效。 + ## 4. 新服务器首次安装 Nginx ```bash diff --git a/web/public/bc406b475509fc295a067baf2eef681a.txt b/verify-root/bc406b475509fc295a067baf2eef681a.txt similarity index 100% rename from web/public/bc406b475509fc295a067baf2eef681a.txt rename to verify-root/bc406b475509fc295a067baf2eef681a.txt diff --git a/web/Dockerfile b/web/Dockerfile index 506048c..ce00d0f 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -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;"]