Trojan — mihomo
mihomo 双端支持 Trojan。出站可走 tcp、ws 与 grpc 传输,并支持 TLS、REALITY、ECH 包装;额外提供 trojan-go 兼容的 ss-opts 层,可在 Trojan 密码握手之上再叠加一层 Shadowsocks 加密。
出站
proxies: 下 type: trojan 条目。内嵌 BasicOption(通用出站 字段)。
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
name | string | (required) | <string> | 唯一的代理名。 |
server | string | (required) | <host> | 上游服务器主机名或 IP。 |
port | int | (required) | <port> | 上游服务器端口。 |
password | string | (required) | <string> | Trojan 密码。 |
alpn | []string | [] | h2 | http/1.1 | TLS 握手时宣告的 ALPN 列表。 |
sni | string | (server name) | <SNI> | TLS Server Name Indication。默认为 `server`。 |
skip-cert-verify | bool | false | true | false | 禁用 TLS 校验(仅供测试)。 |
fingerprint | string | (unset) | <SHA256 hex> | 把服务端 TLS 证书锚定到该指纹。 |
certificate | string | (unset) | <PEM file path> | 客户端证书(mTLS)。 |
private-key | string | (unset) | <key file path> | 与 `certificate` 配对的私钥。 |
udp | bool | false | true | false | 允许 UDP 包经此出站转发。 |
network | string | tcp | tcp | ws | grpc | 底层传输。 |
ech-opts | ECHOptions | (disabled) | ECHOptions | Encrypted Client Hello 配置。 |
reality-opts | RealityOptions | (disabled) | RealityOptions | REALITY 客户端配置。 |
grpc-opts | GrpcOptions | (unset) | GrpcOptions | `network: grpc` 的设置。 |
ws-opts | WSOptions | (unset) | WSOptions | `network: ws` 的设置。 |
ss-opts | TrojanSSOption | (disabled) | TrojanSSOption | 可选的 Shadowsocks-over-Trojan 层(trojan-go 风格)。 |
client-fingerprint | string | (global) | chrome | firefox | safari | ios | edge | random | randomized | uTLS ClientHello 指纹。 |
源码: adapter/outbound/trojan.go:38-58 · 锚定版本 v1.19.27 (5184081)
ss-opts
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
enabled | bool | false | true | false | 在 Trojan 流外再包一层 Shadowsocks。 |
method | string | (unset) | aes-128-gcm | aes-256-gcm | chacha20-ietf-poly1305 | 内层使用的 Shadowsocks AEAD 加密。 |
password | string | (unset) | <string> | 内层 Shadowsocks 的密码(与外层 Trojan 密码相互独立)。 |
源码: adapter/outbound/trojan.go:61-65 · 锚定版本 v1.19.27 (5184081)
入站
listeners: 下 type: trojan 条目。内嵌 BaseOption(listen、 port)。
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
users | []TrojanUser | (required) | [TrojanUser] | 可接受的客户端。 |
ws-path | string | (unset) | /<path> | 该监听器提供的 WebSocket 路径。 |
grpc-service-name | string | (unset) | <name> | 该监听器接受的 gRPC 服务名。 |
certificate | string | (unset) | <PEM file path> | TLS 服务端证书。 |
private-key | string | (unset) | <key file path> | TLS 私钥。 |
client-auth-type | string | (none) | no-client-cert | request-client-cert | require-any-client-cert | verify-client-cert-if-given | require-and-verify-client-cert | mTLS 客户端鉴权模式。 |
client-auth-cert | string | (unset) | <PEM file path> | 作为客户端根的 CA 集合。 |
ech-key | string | (unset) | <ECH config> | Encrypted Client Hello 配置 / 密钥。 |
allow-insecure | bool | false | true | false | 在监听器上跳过 TLS 客户端证书校验(仅供测试)。 |
reality-config | RealityConfig | (disabled) | RealityConfig | REALITY 服务端配置。 |
mux-option | MuxOption | (disabled) | MuxOption | 多路复用设置(sing 风格 mux)。 |
ss-option | TrojanSSOption | (disabled) | TrojanSSOption | Shadowsocks-over-Trojan 兼容层(必须与出站的 `ss-opts` 完全一致)。 |
源码: listener/inbound/trojan.go:12-26 · 锚定版本 v1.19.27 (5184081)
users[]
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
username | string | (unset) | <string> | 显示名。 |
password | string | (required) | <string> | Trojan 密码。 |
源码: listener/inbound/trojan.go:28-31 · 锚定版本 v1.19.27 (5184081)
示例
出站 —— TLS 之上的普通 Trojan:
yaml
proxies:
- name: trojan-srv
type: trojan
server: example.com
port: 443
password: <password>
sni: example.com
udp: true
alpn: [h2, http/1.1]出站 —— WebSocket 之上启用 trojan-go ss-opts 的 Trojan:
yaml
proxies:
- name: trojan-go
type: trojan
server: example.com
port: 443
password: <outer-password>
udp: true
network: ws
sni: example.com
ws-opts:
path: /tj
ss-opts:
enabled: true
method: aes-128-gcm
password: <inner-password>listeners 下的入站:
yaml
listeners:
- name: trojan-in
type: trojan
listen: 0.0.0.0
port: 443
users:
- username: alice
password: <password>
certificate: /etc/mihomo/server.crt
private-key: /etc/mihomo/server.key说明
ss-opts实现了 trojan-go 把 Shadowsocks AEAD 叠加在 Trojan 流上 的模式。外层 Trojan 密码用于握手鉴权;内层 Shadowsocks 密钥负责 载荷加密。入站的ss-option块必须与出站的ss-opts完全一致 (enabled、method、password),否则入站拒绝客户端。- mihomo 没有 Xray 的
fallbacks[]或 sing-box 的fallback_for_alpn等价物。需要 HTTP 回落时,请在 mihomo 之前用独立反向代理终止 TLS。 - 出站的
client-fingerprint是按代理的 uTLS 覆盖。全局默认为global-client-fingerprint。
跨内核说明
- Xray 入站使用
clients[]、支持列表形式fallbacks[]链, 且拒绝任何非空flow。参见 Trojan — Xray-core。 - sing-box 入站使用
users[](name/password),并把 fallback 列表替换为单个默认fallback加按 ALPN 索引的fallback_for_alpn映射。参见 Trojan — sing-box。
源码: adapter/outbound/trojan.go:38-65 · v1.19.27 (5184081)
