Trojan 协议
Trojan 是一个创新的网络代理协议,其最大特色是能够完美伪装为标准的 HTTPS 流量,极难被检测和阻断。
协议特点
- 🎭 完美伪装:伪装为正常的 HTTPS 流量
- 🔐 TLS 加密:基于标准的 TLS 协议
- 🚀 高性能:接近直连的速度表现
- 📡 多传输支持:支持 TCP、WebSocket、gRPC 等
- 🛡️ 抗检测:有效对抗 DPI 和流量分析
配置示例
基础配置
json
{
"outbounds": [
{
"type": "trojan",
"tag": "trojan-out",
"server": "example.com",
"server_port": 443,
"password": "your-password",
"tls": {
"enabled": true,
"server_name": "example.com",
"certificate_path": "/path/to/certificate.crt",
"key_path": "/path/to/private.key"
}
}
]
}WebSocket 传输
json
{
"outbounds": [
{
"type": "trojan",
"tag": "trojan-ws-out",
"server": "example.com",
"server_port": 443,
"password": "your-password",
"transport": {
"type": "ws",
"path": "/trojan",
"headers": {
"Host": "example.com"
}
},
"tls": {
"enabled": true,
"server_name": "example.com"
}
}
]
}gRPC 传输
json
{
"outbounds": [
{
"type": "trojan",
"tag": "trojan-grpc-out",
"server": "example.com",
"server_port": 443,
"password": "your-password",
"transport": {
"type": "grpc",
"service_name": "TunService"
},
"tls": {
"enabled": true,
"server_name": "example.com"
}
}
]
}高级配置
回落配置
json
{
"inbounds": [
{
"type": "trojan",
"tag": "trojan-in",
"listen": "0.0.0.0",
"listen_port": 443,
"users": [
{
"password": "your-password"
}
],
"fallback": {
"alpn": "h2",
"path": "/fallback-path"
},
"tls": {
"enabled": true,
"certificate_path": "/path/to/certificate.crt",
"key_path": "/path/to/private.key"
}
}
]
}多用户配置
json
{
"inbounds": [
{
"type": "trojan",
"tag": "trojan-multi-in",
"listen": "0.0.0.0",
"listen_port": 443,
"users": [
{
"password": "password1"
},
{
"password": "password2"
},
{
"password": "password3"
}
],
"tls": {
"enabled": true,
"certificate_path": "/path/to/certificate.crt",
"key_path": "/path/to/private.key"
}
}
]
}伪装策略
网站回退
- 配置真实网站作为回退目标
- 当检测到非 Trojan 流量时自动转发到回退网站
- 提高伪装真实性
ALPN 协商
- 协商 HTTP/2 协议头
- 与真实 HTTPS 网站保持一致
- 避免流量特征暴露
使用场景
- 企业网络环境
- 严格的网络审查环境
- 需要高度匿名的场景
- 对流量检测敏感的环境
优缺点
优点
- 伪装性极佳,流量看起来完全正常
- 基于标准 TLS,安全性高
- 性能优秀,延迟低
- 抗检测能力强
缺点
- 需要配置 TLS 证书
- 服务器必须绑定域名
- 配置相对复杂
- 端口固定为 443
证书管理
Let's Encrypt 自动证书
bash
# 使用 certbot 获取证书
certbot certonly --standalone -d your-domain.com
# 配置自动续期
0 12 * * * /usr/bin/certbot renew --quiet证书配置建议
- 使用通配符证书支持多子域名
- 配置 OCSP Stapling 提升性能
- 定期更新证书避免过期
- 启用 HSTS 提升安全性
性能优化
服务器优化
- 开启 BBR 拥塞控制
- 优化 TCP 参数
- 配置合适的缓存策略
- 使用高性能 TLS 库
客户端优化
- 启用 TLS 会话复用
- 配置合适的 TLS 版本
- 优化 DNS 解析
- 选择最优的传输方式
安全建议
- 密码强度:使用强密码,定期更换
- 证书安全:妥善保管私钥,定期更新证书
- 网络隔离:避免与其他服务共享端口
- 访问控制:实施 IP 白名单限制
- 监控日志:定期检查访问日志和异常行为