Are you an LLM? You can read better optimized documentation at /zh-TW\wiki\trojan.md for this page in Markdown format
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 白名單限制
- 監控日誌:定期檢查訪問日誌和異常行為