5.9a 远程基础
💡 一句话总结:配置远程模式,实现服务器和 Web 界面的使用。
学完你能做什么
- 能配置远程服务器模式
- 能使用 Web 界面
- 能设置远程访问
- 能管理远程会话
🎒 开始前的准备
确保你已经完成以下事项:
- [ ] 了解 OpenCode 基本配置
- [ ] 准备服务器环境
核心思路
远程模式架构
本地客户端 ←→ 远程服务器模式类型
| 类型 | 说明 | 适用场景 |
|---|---|---|
| SSH | 通过 SSH 连接 | 命令行使用 |
| Web | 通过浏览器访问 | 图形界面 |
| Docker | 容器化部署 | 隔离环境 |
配置结构
服务器配置
yaml
remote:
enabled: true
server:
host: "0.0.0.0"
port: 8080
tls:
enabled: true
cert: "/etc/ssl/certs/opencode.crt"
key: "/etc/ssl/private/opencode.key"
auth:
method: "oauth"
oauth:
provider: "github"
client_id: "${OAUTH_CLIENT_ID}"
client_secret: "${OAUTH_CLIENT_SECRET}"
users:
max_concurrent: 100
session_timeout: 3600SSH 配置
yaml
remote:
ssh:
enabled: true
port: 2222
auth:
- "publickey"
- "password"
keys:
- "/etc/ssh/ssh_host_rsa_key"Web 配置
yaml
remote:
web:
enabled: true
port: 3000
cors:
enabled: true
origins:
- "https://opencode.ai"
- "http://localhost:3000"
ui:
theme: "dark"
language: "zh-CN"部署方式
Docker 部署
bash
# 拉取镜像
docker pull opencode/server:latest
# 运行容器
docker run -d \
--name opencode \
-p 8080:8080 \
-p 2222:2222 \
-v opencode-data:/data \
-e API_KEY="${API_KEY}" \
opencode/server:latestDocker Compose
yaml
version: "3.8"
services:
opencode:
image: opencode/server:latest
ports:
- "8080:8080"
- "2222:2222"
volumes:
- opencode-data:/data
environment:
- API_KEY=${API_KEY}
- DATABASE_URL=postgresql://user:pass@db/opencode
nginx:
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
depends_on:
- opencode使用方法
SSH 连接
bash
# 连接远程 OpenCode
ssh -p 2222 user@opencode.example.com
# 使用指定模型
ssh -p 2222 user@opencode.example.com --model glm-4.7Web 访问
- 打开浏览器访问:
https://opencode.example.com - 使用 GitHub 账号登录
- 开始使用
检查点 ✅
全部通过才能继续
- [ ] 能配置远程服务器
- [ ] 能使用 SSH 连接
- [ ] 能使用 Web 界面
- [ ] 能部署 Docker
本课小结
你学会了:
- 远程模式架构
- 服务器配置
- SSH 和 Web 配置
- Docker 部署
下一课预告
下一课我们将学习远程 API。
📚 更多完整模板:Prompt 模板库

