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;"]