[ PROMPT_NODE_24324 ]
Spectrum 设计模式
[ SKILL_DOCUMENTATION ]
## 常见使用场景
### 1. SSH 服务器保护
**Terraform:**
hcl
resource "cloudflare_spectrum_application" "ssh" {
zone_id = var.zone_id
protocol = "tcp/22"
dns {
type = "CNAME"
name = "ssh.example.com"
}
origin_direct = ["tcp://10.0.1.5:22"]
ip_firewall = true
argo_smart_routing = true
}
**优势:** 隐藏源站 IP、DDoS 防护、IP 防火墙、Argo 智能路由降低延迟
### 2. 游戏服务器
**TypeScript (Minecraft):**
typescript
const app = await client.spectrum.apps.create({
zone_id: 'your-zone-id',
protocol: 'tcp/25565',
dns: { type: 'CNAME', name: 'mc.example.com' },
origin_direct: ['tcp://192.168.1.10:25565'],
proxy_protocol: 'v1', // 保留玩家真实 IP
argo_smart_routing: true,
});
**优势:** DDoS 防护、隐藏源站 IP、通过 Proxy Protocol 获取玩家 IP/封禁、Argo 降低延迟
### 3. MQTT 代理
物联网设备通信。
**TypeScript:**
typescript
const mqttApp = await client.spectrum.apps.create({
zone_id: 'your-zone-id',
protocol: 'tcp/8883', // 普通 MQTT 使用 1883
dns: { type: 'CNAME', name: 'mqtt.example.com' },
origin_direct: ['tcp://mqtt-broker.internal:8883'],
tls: 'full', // 普通 MQTT 使用 'off'
});
**优势:** DDoS 防护、隐藏代理 IP、边缘 TLS 卸载
### 4. SMTP 中继
电子邮件提交(端口 587)。**警告**: 请参阅 [gotchas.md](gotchas.md#smtp-reverse-dns)
**Terraform:**
hcl
resource "cloudflare_spectrum_application" "smtp" {
zone_id = var.zone_id
protocol = "tcp/587"
dns {
type = "CNAME"
name = "smtp.example.com"
}
origin_direct = ["tcp://mail-server.internal:587"]
tls = "full" # 支持 STARTTLS
}
**局限性:**
- Spectrum IP 缺乏反向 DNS (PTR 记录)
- 许多邮件服务器会拒绝没有有效 rDNS 的连接
- 仅适用于内部/受信任的中继
### 5. 数据库代理
MySQL/PostgreSQL。**谨慎使用** - 涉及安全关键。
**PostgreSQL:**
typescript
const postgresApp = await client.spectrum.apps.create({
zone_id: 'your-zone-id',
protocol: 'tcp/5432',
dns: { type: 'CNAME', name: 'postgres.example.com' },
origin_dns: { name: 'db-primary.internal.example.com' },
origin_port: 5432,
tls: 'strict', // 必需
ip_firewall: true, // 必需
});
**MySQL:**
hcl
resource "cloudflare_spectrum_application" "mysql" {
zone_id = var.zone_id
protocol = "tcp/3306"
dns {
type = "CNAME"
name = "mysql.example.com"
}
origin_dns {
name