Clash 的线路配置允许你定义如何处理不同域名和路径的请求,通常用于实现网络代理、负载均衡、访问控制等功能,以下是 Clash 线路配置的常见示例和解释:
- domain: example.com
match:
- type: domain
value: example.com
proxy: http://localhost:108
settings:
dns:
- 8.8.8.8
- 1.1.1.1
http:
- 127...1:80
https:
- 127...1:443
- domain: *.example.com
match:
- type: suffix
value: example.com
proxy: http://localhost:108
settings:
dns:
- 8.8.8.8
- 1.1.1.1
- path: /api
match:
- type: path
value: /api
proxy: http://localhost:108
settings:
http:
- 127...1:80
https:
- 127...1:443
- path: /socket
match:
- type: path
value: /socket
proxy: ws://localhost:808
- domain: google.com
match:
- type: domain
value: google.com
proxy: http://google.com:80
settings:
- type: rewrite
value: google.com
配置说明:
-
domain:匹配特定的域名。- 如果域名与请求域名完全匹配,则应用该路由。
- 如果使用 ,表示匹配所有子域名(如
*.example.com)。
-
match:- 可以是多个匹配条件。
- 常用的匹配类型包括:
type: domain:根据域名匹配。type: suffix:根据域名后缀匹配。type: path:根据路径匹配。type: host:根据请求的主机地址匹配。
-
proxy:- 指定代理地址和端口。
- 可以是本地地址(如
http://localhost:108)或直接指向目标服务器(如http://google.com:80)。
-
settings:- 配置具体的代理设置。
- 常见的设置包括:
dns:配置 DNS 解析地址。http:配置 HTTP 代理设置。https:配置 HTTPS 代理设置。ws:配置 WebSocket 代理设置。rewrite:配置重写规则。
示例说明:
domain: example.com:匹配所有以example.com结尾的域名。path: /api:匹配所有以/api开头的路径。ws://localhost:808:配置 WebSocket 代理。
高级配置:
- 负载均衡:在
settings中添加多个http或https地址,Clash 会根据请求的轮询策略(如轮询、加权)进行负载均衡。 - 域名重写:在
settings中使用rewrite类型,实现域名或路径的重写。 - 过滤:在
route中添加规则,实现对特定域名或路径的访问控制。
常见问题:
- 如果请求的域名不在路由中,Clash 会默认使用原始请求源IP。
- 如果需要更复杂的路由规则,可以通过多个
route条目组合实现。
Clash 的线路配置通过 domain、path 等匹配规则,结合 proxy 和 settings 的设置,允许你灵活配置网络代理、负载均衡、访问控制等功能。









