2026-08-27 14:53:22 +08:00
|
|
|
|
# 模块化部署端口说明
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-09-01 18:05:18 +08:00
|
|
|
|
> 文档定位:**当前部署下的端口规划补充说明**。
|
|
|
|
|
|
> 部署入口与当前推荐方案见 [../DEPLOYMENT.md](../DEPLOYMENT.md),Linux 部署步骤见 [LINUX_SETUP.md](LINUX_SETUP.md)。
|
2026-09-02 18:18:42 +08:00
|
|
|
|
> 本文档负责 **当前模块化部署模式** 下的端口暴露、端口规划与 Nginx / 防火墙层面的补充说明,不再以历史单体 `src.main:app` 作为默认前提。
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
当前推荐部署对象:
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-31 18:01:34 +08:00
|
|
|
|
- frontend(Nginx,同域入口)
|
|
|
|
|
|
- unified backend
|
2026-09-02 18:18:42 +08:00
|
|
|
|
- moldinsight Celery worker(无 HTTP 端口)
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
以下基础设施默认由服务器现有服务提供,不在本项目 compose 中重复部署:
|
|
|
|
|
|
|
|
|
|
|
|
- PostgreSQL
|
|
|
|
|
|
- Redis
|
2026-09-02 18:18:42 +08:00
|
|
|
|
- MinIO / RustFS(moldinsight 需要)
|
2026-08-27 14:53:22 +08:00
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 1. 推荐端口规划
|
|
|
|
|
|
|
|
|
|
|
|
| 组件 | 默认端口 | 说明 |
|
|
|
|
|
|
|---|---:|---|
|
2026-08-31 18:01:34 +08:00
|
|
|
|
| frontend | 80 | 前端 Nginx,同域入口 |
|
|
|
|
|
|
| unified backend | 8000 | 当前推荐统一后端 |
|
2026-09-02 18:18:42 +08:00
|
|
|
|
| moldinsight API | 8000 | 模具分析独立部署时使用 |
|
2026-08-31 18:01:34 +08:00
|
|
|
|
| inventory API | 8001 | 进销存独立部署时使用 |
|
2026-08-27 14:53:22 +08:00
|
|
|
|
| PostgreSQL | 5432 | 共享数据库 |
|
|
|
|
|
|
| Redis | 6379 | 共享队列/缓存 |
|
|
|
|
|
|
| MinIO API | 9000 | 对象存储接口 |
|
|
|
|
|
|
| MinIO Console | 9001 | 对象存储控制台 |
|
|
|
|
|
|
|
|
|
|
|
|
> Celery worker 不直接暴露 HTTP 端口。
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 2. 三种部署模式下的端口
|
|
|
|
|
|
|
2026-09-02 18:18:42 +08:00
|
|
|
|
### 2.1 moldinsight-only
|
2026-08-27 14:53:22 +08:00
|
|
|
|
|
|
|
|
|
|
- 对外开放:`8000`
|
|
|
|
|
|
- 依赖:PostgreSQL、Redis、MinIO/RustFS
|
|
|
|
|
|
- 可选:前置 Nginx 暴露 80/443
|
|
|
|
|
|
|
|
|
|
|
|
### 2.2 inventory-only
|
|
|
|
|
|
|
|
|
|
|
|
- 对外开放:`8001`
|
|
|
|
|
|
- 依赖:PostgreSQL、Redis
|
|
|
|
|
|
- 不要求对象存储
|
|
|
|
|
|
|
|
|
|
|
|
### 2.3 unified
|
|
|
|
|
|
|
2026-09-02 18:18:42 +08:00
|
|
|
|
当前推荐由 unified backend 提供单一后端入口:
|
2026-08-27 14:53:22 +08:00
|
|
|
|
|
2026-09-02 18:18:42 +08:00
|
|
|
|
- 对外开放:`8000`(或由前置 Nginx / 网关统一暴露 80/443)
|
|
|
|
|
|
- 依赖:PostgreSQL、Redis、MinIO / RustFS
|
|
|
|
|
|
- 配套:moldinsight Celery worker 不直接暴露 HTTP 端口
|
2026-08-27 14:53:22 +08:00
|
|
|
|
|
2026-09-02 18:18:42 +08:00
|
|
|
|
在生产环境中,仍推荐通过同域 Nginx / 网关统一对外暴露 80/443,再反代到 unified backend。
|
2026-08-27 14:53:22 +08:00
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 3. Docker Compose 端口来源
|
|
|
|
|
|
|
|
|
|
|
|
当前主部署文件:
|
2026-09-24 15:28:13 +08:00
|
|
|
|
- [docker-compose.yml](../../docker-compose.yml)(unified,默认入口)
|
|
|
|
|
|
- [docker-compose.moldinsight.yml](../../docker-compose.moldinsight.yml)
|
|
|
|
|
|
- [docker-compose.inventory.yml](../../docker-compose.inventory.yml)
|
2026-08-27 14:53:22 +08:00
|
|
|
|
|
2026-09-26 20:45:38 +08:00
|
|
|
|
关键端口映射(默认 10003 / 10004,详见 [.env.example](../../.env.example)):
|
2026-08-27 14:53:22 +08:00
|
|
|
|
|
2026-09-26 20:45:38 +08:00
|
|
|
|
- `FRONTEND_PORT` → frontend Nginx 外部端口(浏览器入口,推荐直接访问)
|
2026-09-26 20:56:20 +08:00
|
|
|
|
- unified backend → **不暴露宿主机端口**,经前端 /api 反代同域访问(docker 网络内 `backend:8000` 互通)
|
|
|
|
|
|
- `MOLDINSIGHT_PORT` → moldinsight-only 模式宿主机端口
|
|
|
|
|
|
- `INVENTORY_PORT` → inventory-only 模式宿主机端口
|
2026-09-02 18:18:42 +08:00
|
|
|
|
- `MOLDINSIGHT_PORT` → moldinsight-only 独立部署端口
|
2026-08-31 18:01:34 +08:00
|
|
|
|
- `INVENTORY_PORT` → inventory-only 独立部署端口
|
2026-08-27 14:53:22 +08:00
|
|
|
|
|
|
|
|
|
|
示例:
|
|
|
|
|
|
|
|
|
|
|
|
```env
|
2026-09-26 20:45:38 +08:00
|
|
|
|
MOLDINSIGHT_PORT=10003
|
|
|
|
|
|
INVENTORY_PORT=10004
|
2026-08-27 14:53:22 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
对应 compose 行为:
|
|
|
|
|
|
|
2026-09-26 20:45:38 +08:00
|
|
|
|
- moldinsight:`${MOLDINSIGHT_PORT:-10003}:8000`
|
|
|
|
|
|
- inventory:`${INVENTORY_PORT:-10004}:8001`
|
2026-08-27 14:53:22 +08:00
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 4. 直接运行时的端口约定
|
|
|
|
|
|
|
2026-09-02 18:18:42 +08:00
|
|
|
|
### moldinsight-only
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-08-27 14:53:22 +08:00
|
|
|
|
uvicorn src.entrypoints.moldinsight:app --host 0.0.0.0 --port 8000
|
2026-02-14 17:15:22 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
### inventory-only
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
uvicorn src.entrypoints.inventory:app --host 0.0.0.0 --port 8001
|
|
|
|
|
|
```
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
如果改端口:
|
2026-09-02 18:18:42 +08:00
|
|
|
|
- moldinsight 改 `--port`
|
2026-08-27 14:53:22 +08:00
|
|
|
|
- inventory 改 `--port`
|
|
|
|
|
|
- 同步更新 Nginx / 防火墙 / 前端 base URL
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
---
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
## 5. 前端联动
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
如果前端与后端分开部署,需要与前端环境变量保持一致。
|
|
|
|
|
|
|
|
|
|
|
|
建议前端支持:
|
|
|
|
|
|
|
|
|
|
|
|
### unified 模式
|
|
|
|
|
|
```env
|
|
|
|
|
|
VITE_API_BASE_URL=https://api.example.com
|
2026-02-14 17:15:22 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
### split 模式
|
|
|
|
|
|
```env
|
|
|
|
|
|
VITE_AUTH_API_BASE_URL=https://auth.example.com
|
2026-09-02 18:18:42 +08:00
|
|
|
|
VITE_MOLDINSIGHT_API_BASE_URL=https://moldinsight.example.com
|
2026-08-27 14:53:22 +08:00
|
|
|
|
VITE_INVENTORY_API_BASE_URL=https://inventory.example.com
|
|
|
|
|
|
```
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
当前详细策略见:
|
2026-09-01 18:05:18 +08:00
|
|
|
|
- [archive/BACKEND_MODULARIZATION_BLUEPRINT.md](../archive/BACKEND_MODULARIZATION_BLUEPRINT.md)
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
## 6. Nginx 示例
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-09-02 18:18:42 +08:00
|
|
|
|
### moldinsight-only
|
2026-08-27 14:53:22 +08:00
|
|
|
|
|
|
|
|
|
|
```nginx
|
2026-02-14 17:15:22 +08:00
|
|
|
|
server {
|
|
|
|
|
|
listen 80;
|
2026-09-02 18:18:42 +08:00
|
|
|
|
server_name moldinsight.example.com;
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
|
|
|
|
|
location / {
|
2026-08-27 14:53:22 +08:00
|
|
|
|
proxy_pass http://127.0.0.1:8000;
|
2026-02-14 17:15:22 +08:00
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
### inventory-only
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
```nginx
|
|
|
|
|
|
server {
|
|
|
|
|
|
listen 80;
|
|
|
|
|
|
server_name inventory.example.com;
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
location / {
|
|
|
|
|
|
proxy_pass http://127.0.0.1:8001;
|
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-02-14 17:15:22 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
---
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
## 7. 防火墙建议
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
如果不通过 Nginx 统一入口而是直接暴露服务端口,则应显式开放:
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
```bash
|
2026-09-02 18:18:42 +08:00
|
|
|
|
# moldinsight
|
2026-08-27 14:53:22 +08:00
|
|
|
|
sudo ufw allow 8000/tcp
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
# inventory
|
|
|
|
|
|
sudo ufw allow 8001/tcp
|
|
|
|
|
|
```
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
生产环境更推荐:
|
|
|
|
|
|
- 外部只开放 80/443
|
|
|
|
|
|
- 内部仅开放 8000/8001 给 Nginx 或内网访问
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
---
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
## 8. 快速检查
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2026-08-27 14:53:22 +08:00
|
|
|
|
curl http://127.0.0.1:8000/health
|
|
|
|
|
|
curl http://127.0.0.1:8001/health
|
2026-02-14 17:15:22 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
如果只部署单模块,只检查对应服务即可。
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
---
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
## 9. 结论
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-08-27 14:53:22 +08:00
|
|
|
|
在当前模块化架构下:
|
2026-02-14 17:15:22 +08:00
|
|
|
|
|
2026-09-02 18:18:42 +08:00
|
|
|
|
- moldinsight 与 inventory 应视为两个独立后端模块
|
|
|
|
|
|
- `unified` 是当前推荐部署模式,由 unified backend 提供单一后端入口
|
|
|
|
|
|
- 端口应按模块与部署模式清晰分配;生产环境通常通过同域 Nginx / 网关统一对外暴露 80/443
|