Skip to content

HTTP & SOCKS — mihomo

mihomo 把入站侧拆成三种监听器类型 —— httpsocksmixed(HTTP+SOCKS 同端口)—— 每种各有独立的 Go 结构体。出站保留 分离:type: httptype: socks5。所有变体都可通过监听器证书 字段启用 TLS。

HTTP 出站

proxies:type: http 条目。内嵌 BasicOption

字段类型默认值允许值描述
namestring(required)<string>唯一的代理名。
serverstring(required)<host>上游 HTTP 代理主机。
portint(required)<port>上游端口。
usernamestring(unset)<string>HTTP Basic 鉴权用户名。
passwordstring(unset)<string>HTTP Basic 鉴权密码。
tlsboolfalsetrue | false用 TLS 包裹上游连接(HTTPS 代理)。
snistring(server)<SNI>TLS Server Name Indication。
skip-cert-verifyboolfalsetrue | false禁用 TLS 校验(仅供测试)。
fingerprintstring(unset)<SHA256 hex>锚定服务端 TLS 证书指纹。
certificatestring(unset)<PEM file path>客户端证书(mTLS)。
private-keystring(unset)<key file path>与 `certificate` 配对的私钥。
headersmap[string]string{}{<header>: <value>}每个请求附加的 HTTP 头。

源码: adapter/outbound/http.go:28-42 · 锚定版本 v1.19.27 (5184081)

SOCKS5 出站

proxies:type: socks5 条目。内嵌 BasicOption

字段类型默认值允许值描述
namestring(required)<string>唯一的代理名。
serverstring(required)<host>上游 SOCKS 主机。
portint(required)<port>上游端口。
usernamestring(unset)<string>SOCKS5 用户名。
passwordstring(unset)<string>SOCKS5 密码。
tlsboolfalsetrue | false用 TLS 包裹 SOCKS 连接。
udpboolfalsetrue | false启用 SOCKS5 UDP-associate。
skip-cert-verifyboolfalsetrue | false禁用 TLS 校验(仅供测试)。
fingerprintstring(unset)<SHA256 hex>锚定服务端 TLS 证书指纹。
certificatestring(unset)<PEM file path>客户端证书(mTLS)。
private-keystring(unset)<key file path>与 `certificate` 配对的私钥。

源码: adapter/outbound/socks5.go:30-43 · 锚定版本 v1.19.27 (5184081)

HTTP 入站

listeners:type: http 条目。内嵌 BaseOption

字段类型默认值允许值描述
usersAuthUsers[]<AuthUsers>可接受的用户。每条目为 `user:pass` 字符串。
certificatestring(unset)<PEM file path>可选 TLS 证书(HTTPS 代理)。需配 `private-key`。
private-keystring(unset)<key file path>TLS 私钥。
client-auth-typestring(none)no-client-cert | request-client-cert | require-any-client-cert | verify-client-cert-if-given | require-and-verify-client-certmTLS 客户端鉴权模式。
client-auth-certstring(unset)<PEM file path>作为客户端根的 CA 集合。
ech-keystring(unset)<ECH config>Encrypted Client Hello 配置 / 密钥。
reality-configRealityConfig(disabled)RealityConfigREALITY 服务端配置。

源码: listener/inbound/http.go:14-23 · 锚定版本 v1.19.27 (5184081)

SOCKS 入站

listeners:type: socks 条目。内嵌 BaseOption

字段类型默认值允许值描述
usersAuthUsers[]<AuthUsers>可接受的用户。
udpboolfalsetrue | false启用 SOCKS5 UDP-associate。
certificatestring(unset)<PEM file path>可选 TLS 证书。
private-keystring(unset)<key file path>TLS 私钥。
client-auth-typestring(none)<see HTTP>同 HTTP 入站。
client-auth-certstring(unset)<PEM file path>同 HTTP 入站。
ech-keystring(unset)<ECH config>Encrypted Client Hello 配置 / 密钥。
reality-configRealityConfig(disabled)RealityConfigREALITY 服务端配置。

源码: listener/inbound/socks.go:14-24 · 锚定版本 v1.19.27 (5184081)

Mixed 入站(HTTP + SOCKS)

listeners:type: mixed 条目。在单一端口上复用 HTTP 与 SOCKS5 —— 客户端请求首字节决定由哪一半处理。

字段类型默认值允许值描述
usersAuthUsers[]<AuthUsers>可接受的用户(HTTP 与 SOCKS 共享)。
udpboolfalsetrue | false在 SOCKS 半部启用 SOCKS5 UDP-associate。
certificatestring(unset)<PEM file path>可选 TLS 证书。
private-keystring(unset)<key file path>TLS 私钥。
client-auth-typestring(none)<see HTTP>同 HTTP 入站。
client-auth-certstring(unset)<PEM file path>同 HTTP 入站。
ech-keystring(unset)<ECH config>Encrypted Client Hello 配置 / 密钥。
reality-configRealityConfig(disabled)RealityConfigREALITY 服务端配置。

源码: listener/inbound/mixed.go:15-25 · 锚定版本 v1.19.27 (5184081)

示例

HTTP 出站:

yaml
proxies:
  - name: http-upstream
    type: http
    server: upstream.example.com
    port: 8080
    username: alice
    password: <password>
    tls: true
    sni: upstream.example.com

支持 UDP 的 SOCKS5 出站:

yaml
proxies:
  - name: socks-upstream
    type: socks5
    server: upstream.example.com
    port: 1080
    username: alice
    password: <password>
    udp: true

供客户端设备使用的 mixed 入站:

yaml
listeners:
  - name: client-mixed
    type: mixed
    listen: 127.0.0.1
    port: 7890
    users:
      - alice:<password>
    udp: true

HTTPS 代理入站(HTTP over TLS):

yaml
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 上的 portsocks-portmixed-port)是声明无鉴权监听器的另一种方式 —— 它们不经过 listeners[]。每个入站只选一种方式。
  • mihomo 顶层 authentication 列表(见 基础) 适用于每个旧式端口(portsocks-portmixed-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)

由 Argsment 出品的 Core Tutorial