HTTP & SOCKS — mihomo
mihomo 把入站侧拆成三种监听器类型 —— http、socks 与 mixed(HTTP+SOCKS 同端口)—— 每种各有独立的 Go 结构体。出站保留 分离:type: http 与 type: socks5。所有变体都可通过监听器证书 字段启用 TLS。
HTTP 出站
proxies: 下 type: http 条目。内嵌 BasicOption。
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
name | string | (required) | <string> | 唯一的代理名。 |
server | string | (required) | <host> | 上游 HTTP 代理主机。 |
port | int | (required) | <port> | 上游端口。 |
username | string | (unset) | <string> | HTTP Basic 鉴权用户名。 |
password | string | (unset) | <string> | HTTP Basic 鉴权密码。 |
tls | bool | false | true | false | 用 TLS 包裹上游连接(HTTPS 代理)。 |
sni | string | (server) | <SNI> | TLS Server Name Indication。 |
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` 配对的私钥。 |
headers | map[string]string | {} | {<header>: <value>} | 每个请求附加的 HTTP 头。 |
源码: adapter/outbound/http.go:28-42 · 锚定版本 v1.19.27 (5184081)
SOCKS5 出站
proxies: 下 type: socks5 条目。内嵌 BasicOption。
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
name | string | (required) | <string> | 唯一的代理名。 |
server | string | (required) | <host> | 上游 SOCKS 主机。 |
port | int | (required) | <port> | 上游端口。 |
username | string | (unset) | <string> | SOCKS5 用户名。 |
password | string | (unset) | <string> | SOCKS5 密码。 |
tls | bool | false | true | false | 用 TLS 包裹 SOCKS 连接。 |
udp | bool | false | true | false | 启用 SOCKS5 UDP-associate。 |
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` 配对的私钥。 |
源码: adapter/outbound/socks5.go:30-43 · 锚定版本 v1.19.27 (5184081)
HTTP 入站
listeners: 下 type: http 条目。内嵌 BaseOption。
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
users | AuthUsers | [] | <AuthUsers> | 可接受的用户。每条目为 `user:pass` 字符串。 |
certificate | string | (unset) | <PEM file path> | 可选 TLS 证书(HTTPS 代理)。需配 `private-key`。 |
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 配置 / 密钥。 |
reality-config | RealityConfig | (disabled) | RealityConfig | REALITY 服务端配置。 |
源码: listener/inbound/http.go:14-23 · 锚定版本 v1.19.27 (5184081)
SOCKS 入站
listeners: 下 type: socks 条目。内嵌 BaseOption。
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
users | AuthUsers | [] | <AuthUsers> | 可接受的用户。 |
udp | bool | false | true | false | 启用 SOCKS5 UDP-associate。 |
certificate | string | (unset) | <PEM file path> | 可选 TLS 证书。 |
private-key | string | (unset) | <key file path> | TLS 私钥。 |
client-auth-type | string | (none) | <see HTTP> | 同 HTTP 入站。 |
client-auth-cert | string | (unset) | <PEM file path> | 同 HTTP 入站。 |
ech-key | string | (unset) | <ECH config> | Encrypted Client Hello 配置 / 密钥。 |
reality-config | RealityConfig | (disabled) | RealityConfig | REALITY 服务端配置。 |
源码: listener/inbound/socks.go:14-24 · 锚定版本 v1.19.27 (5184081)
Mixed 入站(HTTP + SOCKS)
listeners: 下 type: mixed 条目。在单一端口上复用 HTTP 与 SOCKS5 —— 客户端请求首字节决定由哪一半处理。
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
users | AuthUsers | [] | <AuthUsers> | 可接受的用户(HTTP 与 SOCKS 共享)。 |
udp | bool | false | true | false | 在 SOCKS 半部启用 SOCKS5 UDP-associate。 |
certificate | string | (unset) | <PEM file path> | 可选 TLS 证书。 |
private-key | string | (unset) | <key file path> | TLS 私钥。 |
client-auth-type | string | (none) | <see HTTP> | 同 HTTP 入站。 |
client-auth-cert | string | (unset) | <PEM file path> | 同 HTTP 入站。 |
ech-key | string | (unset) | <ECH config> | Encrypted Client Hello 配置 / 密钥。 |
reality-config | RealityConfig | (disabled) | RealityConfig | REALITY 服务端配置。 |
源码: listener/inbound/mixed.go:15-25 · 锚定版本 v1.19.27 (5184081)
示例
HTTP 出站:
proxies:
- name: http-upstream
type: http
server: upstream.example.com
port: 8080
username: alice
password: <password>
tls: true
sni: upstream.example.com支持 UDP 的 SOCKS5 出站:
proxies:
- name: socks-upstream
type: socks5
server: upstream.example.com
port: 1080
username: alice
password: <password>
udp: true供客户端设备使用的 mixed 入站:
listeners:
- name: client-mixed
type: mixed
listen: 127.0.0.1
port: 7890
users:
- alice:<password>
udp: trueHTTPS 代理入站(HTTP over TLS):
listeners:
- name: https-proxy
type: http
listen: 0.0.0.0
port: 8443
users:
- alice:<password>
certificate: /etc/mihomo/server.crt
private-key: /etc/mihomo/server.key说明
- 这里的
users:是user:pass字符串列表 —— 不是结构化对象数组。:分隔符必须存在。空列表禁用鉴权。 mixed监听器同一端口同时接受 HTTP 与 SOCKS5,由首字节检测在 监听器内部判定。- 顶层快捷字段(根
RawConfig上的port、socks-port、mixed-port)是声明无鉴权监听器的另一种方式 —— 它们不经过listeners[]。每个入站只选一种方式。 - mihomo 顶层
authentication列表(见 基础) 适用于每个旧式端口(port、socks-port、mixed-port),但 不 适用于listeners:条目 —— 它们各自有users字段。
跨内核说明
- Xray-core 把 HTTP 与 SOCKS 放在分开的源文件中,使用
accounts[](每条{user, pass}),且没有内置 "mixed" 入站。 参见 HTTP & SOCKS — Xray-core。 - sing-box 也提供
mixed入站,users[]携带结构化{username, password}对象。字段名为 snake_case。参见 HTTP & SOCKS — sing-box。
源码: adapter/outbound/http.go:28-42 · v1.19.27 (5184081)
