Are you an LLM? You can read better optimized documentation at /en\wiki\trojan.md for this page in Markdown format
Trojan protocol
Trojan is an innovative proxy protocol whose defining feature is the ability to blend in perfectly with standard HTTPS traffic, making it very hard to detect or block.
Characteristics
- 🎭 Perfect camouflage: looks like ordinary HTTPS traffic
- 🔐 TLS encryption: built on standard TLS
- 🚀 High performance: speeds close to a direct connection
- 📡 Many transports: TCP, WebSocket, gRPC and more
- 🛡️ Hard to detect: effective against DPI and traffic analysis
Configuration examples
Basic configuration
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 transport
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 transport
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"
}
}
]
}Advanced configuration
Fallback
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"
}
}
]
}Multiple users
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"
}
}
]
}Camouflage strategy
Website fallback
- Point the fallback at a real website
- Non-Trojan traffic is forwarded to that site automatically
- Makes the camouflage much more convincing
ALPN negotiation
- Negotiate the HTTP/2 protocol header
- Stay consistent with real HTTPS sites
- Avoid exposing traffic fingerprints
Use cases
- Corporate networks
- Heavily censored networks
- Scenarios that require strong anonymity
- Environments sensitive to traffic inspection
Pros and cons
Pros
- Outstanding camouflage: traffic looks entirely normal
- Built on standard TLS, so security is strong
- Excellent performance and low latency
- Strong resistance to detection
Cons
- Requires a TLS certificate
- The server must be bound to a domain name
- Configuration is fairly involved
- Normally pinned to port 443
Certificate management
Automatic certificates with Let's Encrypt
bash
# Obtain a certificate with certbot
certbot certonly --standalone -d your-domain.com
# Configure automatic renewal
0 12 * * * /usr/bin/certbot renew --quietCertificate tips
- Use a wildcard certificate if you serve multiple subdomains
- Enable OCSP stapling for better performance
- Renew certificates before they expire
- Enable HSTS for extra security
Performance tuning
Server side
- Enable BBR congestion control
- Tune TCP parameters
- Configure a sensible cache policy
- Use a high-performance TLS library
Client side
- Enable TLS session resumption
- Choose an appropriate TLS version
- Optimize DNS resolution
- Pick the best transport
Security recommendations
- Password strength: use strong passwords and rotate them
- Certificate safety: protect private keys and renew certificates
- Port isolation: do not share the port with other services
- Access control: enforce IP allowlists
- Log monitoring: review access logs and look for anomalies