Files
leaudit-platform-backend/docs/Collabora/部署排障/IP链路部署与排障.md
T

248 lines
5.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Collabora IP链路部署与排障
## 本次目标
将文档预览/编辑链路统一收口到 `http://172.16.0.59:5173`,避免 `nas.7bm.co` 与内网 IP 混用导致:
- Collabora iframe 打不开
- `chrome-error://chromewebdata/`
- `refused to connect` / `拒绝连接`
- WOPI 已经 200,但浏览器侧仍然失败
## 最终生效配置
### 1. 前端环境变量
文件:`legal-platform-frontend/.env`
关键项:
```env
API_BACKEND_TARGET=http://172.16.0.59:8096
APP_URL=http://172.16.0.59:5173
DOCUMENT_URL=http://172.16.0.59:8096/docauditai/
COLLABORA_URL=http://172.16.0.59:5173
```
说明:
- `APP_URL` 决定 WOPI 回调地址 `WOPISrc`
- `COLLABORA_URL` 决定 iframe 中加载的 `cool.html`
- 如果这里仍然写域名,最终会重新生成域名链路
### 2. nginx 代理
文件:`deploy/collabora-proxy/conf.d/collabora.conf`
必须代理这些路径:
- `/wopi/`
- `/browser/`
- `/cool/`
- `/coolws/`
- `/hosting/`
- `/loleaflet/`
- `/`
关键点:
- Collabora 相关 `Host` / `X-Forwarded-Host` 统一写成 `172.16.0.59:5173`
- `proxy_redirect` 统一改写到 `http://172.16.0.59:5173/`
- `/coolws/` 不能漏,否则 websocket 子通道会 404
### 3. Collabora 白名单与 CSP
文件:`/home/wren-dev/Porject/collabora-backup/coolwsd-config/coolwsd.xml`
关键项:
```xml
<content_security_policy>frame-ancestors http://172.16.0.59:5173;</content_security_policy>
```
```xml
<alias_groups mode="groups">
<group>
<host desc="LAN Frontend" allow="true">http://172\.16\.0\.59:5173</host>
</group>
</alias_groups>
```
说明:
- 不再保留 `nas.7bm.co`,避免域名/IP 混用
- 不再使用带端口正则的 alias,之前会触发 `Bad URI syntax` / `Invalid regular expression`
### 4. Compose 参数
文件:`/home/wren-dev/Porject/collabora-backup/docker-compose.yml`
当前使用:
```yaml
extra_params=--o:ssl.enable=false --o:ssl.termination=false --o:logging.level=warning --o:security.seccomp=false
```
说明:
- 已移除旧的 `--o:net.frame_ancestors=http://*`
- 该参数会污染最终 CSP,导致浏览器报 `frame-ancestors` 违规
## 本次修复过的问题
### 问题 1:登录跳转到了 `localhost:5193`
现象:
- 访问 `5173` 后,响应头返回 `Location: http://localhost:5193/login?...`
原因:
- 代理层转发头不完整
- Next 在开发环境下生成了错误绝对跳转
处理:
-`X-Forwarded-Host` / `X-Forwarded-Port`
-`proxy_redirect`
### 问题 2`/coolws/` 没代理
现象:
- `WOPI` 已通
- Collabora 页面仍起不来
原因:
- `coolws/newchild` 被打到 Next,返回 404
处理:
-`/coolws/` 增加代理到 `127.0.0.1:9980`
### 问题 3allowed host 正则写坏
现象:
- Collabora 日志出现:
- `Invalid regular expression for allowed host`
- `Bad URI syntax`
原因:
- 使用了复杂 alias 正则:
- `http://172\.16\.0\.[0-9]{1,3}(:[0-9]{1,5})?`
处理:
- 改为显式 host,不再用该正则
### 问题 4:浏览器控制台报 CSP / frame-ancestors 错误
现象:
- `Framing 'http://172.16.0.59:5173/' violates Content Security Policy directive...`
- `chrome-error://chromewebdata/`
原因:
- Compose 里的旧 `net.frame_ancestors=http://*`
- `coolwsd.xml` 里的 CSP 与实际 host 混用
- 旧标签页中还混有 `nas.7bm.co`
处理:
- 删除旧 `net.frame_ancestors`
- `content_security_policy` 只允许 `http://172.16.0.59:5173`
- 重建容器而不是简单 restart
## 重启方式
### 前后端
```bash
./leaudit.sh restart
```
### Collabora
```bash
cd /home/wren-dev/Porject/collabora-backup
docker-compose up -d --force-recreate collabora
```
### 代理
```bash
docker restart leaudit-collabora-proxy
```
## 验证命令
### 前端入口
```bash
curl -I http://172.16.0.59:5173/
```
期望:
- 跳转到 `http://172.16.0.59:5173/login?...`
### Collabora 发现接口
```bash
curl -I http://172.16.0.59:5173/hosting/discovery
```
期望:
- `200 OK`
### Collabora 页面入口
```bash
curl -I http://172.16.0.59:5173/browser/dist/cool.html
```
期望:
- `200 OK`
- `Content-Security-Policy` 里只出现 `172.16.0.59:5173`
### WOPI 文件接口
由页面实际触发,日志里应看到:
- `GET /wopi/files/... 200`
## 浏览器测试要求
为避免旧的 `nas.7bm.co` 页面上下文污染:
1. 关闭旧标签页
2. 打开无痕窗口
3. 直接访问 `http://172.16.0.59:5173/login`
4. 登录后进入文档页
5. 不要从 `nas.7bm.co` 页面里跳转到 IP 页面
## 已做的前端小收口
文件:`legal-platform-frontend/lib/services/collabora.config.server.ts`
处理:
- 移除了 `ui_defaults` 中的 `SavedUIState=false`
原因:
- Collabora 会打印:`unknown UI default's component SavedUIState`
- 该项不是必须,去掉后能减少无关告警
## 后续建议
- 如果后面要回切域名方案,不要与 IP 方案混用
- 需要整套一起回切:前端 `.env`、nginx、Collabora host/CSP 同步改回
- 如果当前 IP 方案稳定,可单独保留一份 docker 与 nginx 配置快照