一般来说,机场提供的配置文件一键订阅会处理好代理和分流的问题,足够使用了。但由于包括但不限于:
有多个机场、或者有自建的节点想同时使用
机场的规则过于臃肿、或者不能涵盖自己需求
等原因,总有人想要写一份完全符合自己需要的配置。我就一直有这种想法,最近终于付诸实施,并且还顺便了解到如何将这样一份配置托管到网上,让不同设备可以通过链接直接订阅,因此在这里简单记录一下过程,方便有同样需求的人参考。
一、Proxy Provider 转换
Proxy Provider 是 Clash 提供的一项功能,可以单独引入一些代理服务器信息,插入到当前配置文件中以供使用。有的机场直接提供了 Proxy Provider 链接,有的没有,在后一种情况下就需要将机场的配置文件订阅链接加以转换,提取出其中代理服务器部分。
Proxy Provider Converter 是一项提供这种转换的公开服务,可以直接使用。然而这样有两个问题:(1) 该服务的提供者可以看到你的订阅地址 (2) vercel.app 在国内无法访问。这样编写的配置文件需要可用代理才能下载代理信息,而又要下载了代理信息才能获得可用代理。(扔桌子.jpg)

好在开发者提供了简便的自行部署方法。根据网页上的说明部署到 Vercel 后就解决了上述第一个问题,而要解决第二个问题就需要有一个自己的域名,并在 DNS 解析处添加一项 CNAME 记录,指向 cname-china.vercel-dns.com
,随后在 Vercel 自己部署的项目中找到 Settings-Domains
,添加自己刚刚做好解析的完整域名,就能通过这个没有被墙的域名使用转换服务。如果你没有域名,又信任我不会偷看你的订阅的话,也可以使用我自己的这个:https://a.ppconverter.eu.org。
二、编写配置文件
Clash 配置文件的基本格式官方 Wiki 有足够详尽的说明,有兴趣可以自己阅读,这里就不重复解释了,直接提供一个通用的配置(注意需要在 proxy-providers
中粘贴自己转换得到的链接):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
| mixed-port: 7890 allow-lan: true mode: rule log-level: info ipv6: false
proxy-providers: myproxy: type: http url: https://example.com interval: 172800 path: ./myproxy.yaml health-check: enable: true interval: 600 url: http://www.gstatic.com/generate_204
proxy-groups: - name: "PROXY" type: select use: - myproxy - name: "Ads" type: select proxies: - REJECT - PROXY - DIRECT - name: "Apple" type: select proxies: - DIRECT - PROXY - name: "Telegram" type: select use: - myproxy proxies: - PROXY - name: "YouTube" type: select use: - myproxy proxies: - PROXY - name: "GlobalMedia" type: select use: - myproxy proxies: - PROXY - name: "Steam" type: select use: - myproxy proxies: - DIRECT - PROXY - name: "Others" type: select proxies: - PROXY - DIRECT
rule-providers: reject: type: http behavior: domain url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/reject.txt" path: ./ruleset/reject.yaml interval: 86400
icloud: type: http behavior: domain url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/icloud.txt" path: ./ruleset/icloud.yaml interval: 86400
apple: type: http behavior: domain url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/apple.txt" path: ./ruleset/apple.yaml interval: 86400
streaming: type: http behavior: classical url: "https://ghproxy.com/https://raw.githubusercontent.com/DivineEngine/Profiles/master/Clash/RuleSet/StreamingMedia/Streaming.yaml" path: ./ruleset/streaming.yaml interval: 86400 steam: type: http behavior: classical url: 'https://ghproxy.com/https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Clash/Steam/Steam.yaml' path: ./ruleset/steam.yaml interval: 86400
steamCN: type: http behavior: classical url: 'https://ghproxy.com/https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Clash/SteamCN/SteamCN.yaml' path: ./ruleset/steamCN.yaml interval: 86400 youtube: type: http behavior: classical url: 'https://ghproxy.com/https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Clash/YouTube/YouTube.yaml' path: ./ruleset/youtube.yaml interval: 86400
proxy: type: http behavior: domain url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/proxy.txt" path: ./ruleset/proxy.yaml interval: 86400
direct: type: http behavior: domain url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/direct.txt" path: ./ruleset/direct.yaml interval: 86400
private: type: http behavior: domain url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/private.txt" path: ./ruleset/private.yaml interval: 86400
telegramcidr: type: http behavior: ipcidr url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/telegramcidr.txt" path: ./ruleset/telegramcidr.yaml interval: 86400
lancidr: type: http behavior: ipcidr url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/lancidr.txt" path: ./ruleset/lancidr.yaml interval: 86400
applications: type: http behavior: classical url: "https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/applications.txt" path: ./ruleset/applications.yaml interval: 86400
rules: - RULE-SET,applications,DIRECT - DOMAIN,clash.razord.top,DIRECT - DOMAIN,yacd.haishan.me,DIRECT - RULE-SET,private,DIRECT - RULE-SET,reject,Ads - RULE-SET,icloud,Apple - RULE-SET,apple,Apple - RULE-SET,youtube,YouTube - RULE-SET,streaming,GlobalMedia - RULE-SET,steamCN,DIRECT - RULE-SET,steam,Steam - RULE-SET,proxy,PROXY - RULE-SET,direct,DIRECT - RULE-SET,telegramcidr,Telegram - RULE-SET,lancidr,DIRECT - GEOIP,CN,DIRECT - MATCH,Others
|
我没有能力手写成千上万的规则,而是引入了与 Proxy Provider 类似的 Rule Provider,直接使用网络上的第三方规则集。Clash 的规则是从前到后依次匹配的,已经匹配到的流量就不会向后继续匹配。值得注意的情况有:
iCloud 与其他一些苹果服务有专门的 Apple
代理组,可以选择直连或代理(一般而言直连就够了);
尽管 streaming
规则集中包括了 YouTube,但我还是将 YouTube 规则单列出来放在前面,如果有送中节点的话可以免广告看 YouTube;
Steam 登录和下载一直是老大难问题。以前使用机场规则时,我的经验是(国区)需要在登录时将 Steam
和 Others
代理组都选为直连,登录后再改为需要的代理节点,这样才不会无法登录,下载节点是国内,同时也能访问好友列表、创意工坊等内容。如今自己写的规则先将 steamCN 规定为直连,再把剩下的 steam 流量用一个代理组选择代理节点,体验就基本完美了。
当然这只是一个追求最大通用性的内容,你也可以自行修改增加需要的规则。比如我实际使用的规则中还包括一条 DOMAIN,***.sharepoint.com,MyOneDrive
,再在 proxy-groups
里添加 MyOneDrive
这一代理组和所需的节点,这样在我向 5T OneDrive 上传视频时可以切换为直连节约流量,观看时又打开代理来保障体验。不过请注意,出于规则匹配顺序的原因,一般自己修改的这些规则都应该放在较为靠前的位置。另外,规则集可以在这些地方找到:
https://github.com/Loyalsoldier/clash-rules 简洁明了,注意需要设置为 behavior: domain
https://github.com/blackmatrix7/ios_rule_script/tree/master/rule/Clash 非常全面,behavior: classical
https://github.com/DivineEngine/Profiles/tree/master/Clash/RuleSet 知名选择,behavior: classical
这些规则集提供的 https://raw.githubusercontent.com
地址在国内通常无法访问,只需要在前面加上 https://ghproxy.com/
,组成 https://ghproxy.com/https://raw.githubusercontent.com/Loyalsoldier/clash-rules/release/proxy.txt
这样的 URL 就好。
三、托管并订阅
得到这样一份可以使用的配置文件后,当然可以在各个设备间手动拷贝并导入软件,但这样本身很麻烦,如果之后需要修改的话还要重复一遍流程,更加糟糕。因此,我们最好把它托管到互联网上,让各个设备订阅托管的网址,修改也只需要变更网络上这一份,完成后各个设备更新一下订阅就好。
打开 GitHub Gist,Gist description
不用填,Filename including extension...
填入包括拓展名的文件全名,如 myconfig.yaml
,将配置文件的全部内容粘贴进去,最后点右下角绿色按钮发布。

然后打开刚刚发布的 Gist,点击右上角的 Raw
,复制当前的的地址,如:
https://gist.githubusercontent.com/githubusername/1234567890/raw/0987654321/myconfig.yaml
将 /raw/
之后的第二串随机数删除,得到形如:
https://gist.githubusercontent.com/githubusername/1234567890/raw/myconfig.yaml
的 URL。在任意使用 Clash Premium 或 Meta 内核的 Clash 图形化客户端中(如果你不知道你用的是哪种内核,那极大概率就是 Premium)添加这一订阅链接,等所需文件下载完成后就可以正常使用了。