refactor(deploy): ?????????? Nginx ????
Made-with: Cursor
This commit is contained in:
@@ -81,34 +81,15 @@ sudo systemctl start nginx
|
||||
- **应用内 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 入口)
|
||||
## 6. 单实例:宿主机 Nginx 占 443(与 `pull-and-restart.sh` / `restart.sh` 自动切换)
|
||||
|
||||
不再使用容器 **`yh_nginx`**,由**宿主机 Nginx** 监听 **443**,把流量转到本机回环上的 **`web` / `admin` / `api` 容器**。
|
||||
逻辑由 **`scripts/lib-yh-compose-deploy.sh`** 统一处理(无需单独启动脚本):
|
||||
|
||||
1. **证书**:同上,放在 `/etc/ssl/yh_web/yuheng.yuxindazhineng.com/`。
|
||||
2. **合并 Compose**(为容器绑定回环端口,并禁用 compose 内 Nginx):
|
||||
1. **启动前**:`docker compose … down --remove-orphans`,只停本项目容器,**不**对宿主机 `nginx` 做 `start/stop`。
|
||||
2. **`systemctl` 显示宿主机 Nginx 已运行**:只起 `mongo api web admin`,**不起**容器 `yh_nginx`;从 **`nginx/yuheng.host.conf`** 生成 `/etc/nginx/conf.d/<域名>.conf` 并 **`nginx -t` + `reload`**(不重载则无法指向新回环端口)。
|
||||
3. **宿主机 Nginx 未运行**:起完整栈(**`--profile compose-internal-nginx`**,含容器 `yh_nginx` 终止 TLS)。
|
||||
4. **证书**:同上,`/etc/ssl/yh_web/yuheng.yuxindazhineng.com/`;`pull-and-restart.sh` / `restart.sh` 仍会同步仓库内证书到该目录。
|
||||
|
||||
```bash
|
||||
docker compose -f docker-compose.yml -f docker-compose.host-nginx.yml up -d mongo api web admin
|
||||
```
|
||||
**回环端口**(与 `nginx/yuheng.host.conf` 一致):API `127.0.0.1:8088`,前台 `9080`,后台 `9081`。
|
||||
|
||||
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. **与「方式 B(8443)」的区别**:方式 B 是「宿主机 Nginx → 容器 Nginx → 各服务」两层;本节是「宿主机 Nginx → 各服务」**一层**,不再起 `yh_nginx`。
|
||||
**与「方式 B(8443)」**:方式 B 是宿主机 → 容器 Nginx → 各服务;本节是宿主机 → 各服务,**一层**。
|
||||
|
||||
Reference in New Issue
Block a user