feat(deploy): 宿主机单 Nginx 方案、compose 覆盖与启动脚本

Made-with: Cursor
This commit is contained in:
whm
2026-03-27 11:15:00 +08:00
parent 2f78fd0d52
commit 38c4c465c5
4 changed files with 209 additions and 0 deletions

View File

@@ -80,3 +80,35 @@ sudo systemctl start nginx
- **要求**:托管 **web 前台** 的站点必须使用 **`try_files $uri $uri/ /index.html;`**(见仓库 `nginx/web.conf``web/Dockerfile` 内嵌配置)。若你自建 Nginx请对照修改后再 `nginx -t` 并重载。
- **应用内 404**:在 SPA 已正确回退的前提下,未在后台发布的路径会由前端路由进入 **「页面不存在」** 页(`NotFound.vue`),与上述 nginx 404 不同。
- **Compose 部署**`web` 容器实际加载的是 **`deploy/web/default.conf`**(见 `docker-compose.yml` 挂载)。若线上仍对 `/test` 等返回 **nginx 404**,请把仓库里最新的 `deploy/web/default.conf` 同步到服务器对应路径后,执行 `docker compose restart web`(或重建 `yh_web` 容器)。
## 6. 单实例:仅宿主机 Nginx推荐一台机一个 443 入口)
不再使用容器 **`yh_nginx`**,由**宿主机 Nginx** 监听 **443**,把流量转到本机回环上的 **`web` / `admin` / `api` 容器**。
1. **证书**:同上,放在 `/etc/ssl/yh_web/yuheng.yuxindazhineng.com/`
2. **合并 Compose**(为容器绑定回环端口,并禁用 compose 内 Nginx
```bash
docker compose -f docker-compose.yml -f docker-compose.host-nginx.yml up -d mongo api web admin
```
3. **一键脚本**(启动容器 + 写入宿主机站点配置并重载 Nginx
```bash
chmod +x scripts/start-with-host-nginx.sh
./scripts/start-with-host-nginx.sh
```
脚本会把 `nginx/yuheng.host.conf` 中的 `__VERIFY_ROOT__` 替换为项目下 `verify-root` 绝对路径,并写入 `/etc/nginx/conf.d/yuheng.yuxindazhineng.com.conf`(需 **sudo**)。若不想自动改 Nginx`INSTALL_NGINX_CONF=0 ./scripts/start-with-host-nginx.sh`
4. **回环端口约定**(与 `nginx/yuheng.host.conf` 一致):
| 服务 | 本机地址 |
|------|----------|
| API | `127.0.0.1:8088` |
| 前台静态 | `127.0.0.1:9080` |
| 后台静态 | `127.0.0.1:9081` |
5. **若仍要用容器里的 yh_nginx**(旧方案):`docker compose --profile compose-internal-nginx up -d`,此时会与宿主机抢 **443**,二选一。
6. **与「方式 B8443」的区别**:方式 B 是「宿主机 Nginx → 容器 Nginx → 各服务」两层;本节是「宿主机 Nginx → 各服务」**一层**,不再起 `yh_nginx`