feat: 资源部署

This commit is contained in:
R524809
2026-02-02 13:19:46 +08:00
parent 27f7404816
commit b13ab6f9fb
7 changed files with 359 additions and 16 deletions
@@ -0,0 +1,129 @@
# 用本机 Nginx 测试 pipi-assets 配置
按顺序做下面几步即可。
---
## 1. 检查是否已安装 Nginx
在终端执行:
```bash
nginx -v
```
- **有版本号**(如 `nginx version: nginx/1.27.5`)→ 已安装,跳到第 2 步。
- **报错 command not found** → 需要先安装。Mac 推荐用 Homebrew
```bash
brew install nginx
```
---
## 2. 确认资源目录存在
本配置会使用项目下的 `pipi-assets` 目录。若还没有,先执行一次:
```bash
cd platform-pipi/packages/voice-production
pnpm run deploy-assets:local
```
这样会生成 `pipi-assets/`(内含 `char/`、`voice/` 等)。
---
## 3. 让主 Nginx 加载本项目的配置
你的 Nginx 主配置在 **Homebrew** 安装时一般是:
- Apple Silicon`/opt/homebrew/etc/nginx/nginx.conf`
- Intel`/usr/local/etc/nginx/nginx.conf`
任选一种方式,让主配置把「本项目里的 pipi-assets 配置」包含进去。
### 方式 A:在主配置里加一行 include(推荐)
1. 用编辑器打开主配置,例如:
```bash
open -e /opt/homebrew/etc/nginx/nginx.conf
```
(Intel 机器把路径改成 `/usr/local/etc/nginx/nginx.conf`
2. 在 `http { ... }` 块里找合适位置(例如在 `include servers/*;` 那一行**上面**),加一行:
```nginx
include /Users/joey-xd/sites/pipi-learn/platform-pipi/packages/voice-production/scripts/nginx-pipi-assets-local.conf;
```
注意把路径改成你本机实际的项目路径。
3. 保存退出。
### 方式 B:放到 Nginx 的 servers 目录
1. 若没有 `servers` 目录,先建一个:
```bash
sudo mkdir -p /opt/homebrew/etc/nginx/servers
```
Intel 用 `/usr/local/etc/nginx/servers`
2. 做一份软链,指向项目里的本地配置:
```bash
sudo ln -sf /Users/joey-xd/sites/pipi-learn/platform-pipi/packages/voice-production/scripts/nginx-pipi-assets-local.conf /opt/homebrew/etc/nginx/servers/pipi-assets.conf
```
主配置里已有 `include servers/*;` 时会自动加载。
---
## 4. 检查配置并重载 Nginx
```bash
# 检查语法是否正确
nginx -t
# 若无报错,重载 Nginx(不中断已有连接)
nginx -s reload
```
若你是用 `brew services start nginx` 启用的,可以改为:
```bash
brew services restart nginx
```
---
## 5. 在浏览器或终端里测试
本地站点监听 **8081 端口**,用 `localhost` 即可访问(无需改 hosts)。
- 健康检查:
**http://localhost:8081/health**
应看到页面内容:`ok`
- 角色 JSON
**http://localhost:8081/char/char_introduce.json**
应返回 JSON 内容
- 语音文件(示例):
**http://localhost:8081/voice/一\_4e00.mp3**
应能播放或下载
终端快速验证:
```bash
curl -s http://localhost:8081/health
curl -s -o /dev/null -w "%{http_code}" http://localhost:8081/char/char_introduce.json
```
---
## 说明
- **端口**:使用 8081 是为了不和 80 端口上已有的其他站点(如 simulation.data-platform.local 等)冲突。
- **配置文件**`nginx-pipi-assets.conf` 是给服务器部署用的(80 端口 + 二级域名);`nginx-pipi-assets-local.conf` 是给本机测试用的(8081 + localhost),路径已指向项目下的 `pipi-assets`。