raw.githubusercontent.com 国内加速完全方案 2026

raw.githubusercontent.com 是 GitHub 上 README、配置文件、规则集、shell 脚本、模型权重的主要分发域名。国内打开它经常超时,导致 curl | bash 类的安装脚本直接挂掉。本文给 5 种 2026 实测可用方案。

一、5 种方案速览

#方案转换方式国内可用性大文件支持
1raw.staticdn.net 反代替换域名★★★★
2raw.kkgithub.com 镜像替换域名★★★
3jsDelivr CDN重写 URL 格式★★★✗(50MB 上限)
4ghfast.top 通用前缀加 URL 前缀★★★★
5GitHub520 hosts + 走直连改 /etc/hosts★★

二、方案 1:raw.staticdn.net(最简单)

直接替换域名:

原:https://raw.githubusercontent.com/libfuse/sshfs/master/README.md
改:https://raw.staticdn.net/libfuse/sshfs/master/README.md

适合 wget / curl / 浏览器:

curl -O https://raw.staticdn.net/owner/repo/branch/file

三、方案 2:raw.kkgithub.com

KKGitHub 同样把 raw 1:1 反代:

原:https://raw.githubusercontent.com/owner/repo/main/file
改:https://raw.kkgithub.com/owner/repo/main/file

部分场景比 staticdn 快,可作备份。

四、方案 3:jsDelivr(适合前端 / 小文件)

jsDelivr 把 GitHub 仓库当成 npm-like 包代理:

原:https://raw.githubusercontent.com/<owner>/<repo>/<branch>/<file>
改:https://cdn.jsdelivr.net/gh/<owner>/<repo>@<branch>/<file>

实例:

原:https://raw.githubusercontent.com/anuraghazra/github-readme-stats/master/README.md
改:https://cdn.jsdelivr.net/gh/anuraghazra/github-readme-stats@master/README.md

优势:

  • 国内 CDN 节点多,速度快
  • 支持指定 tag / commit hash(@v1.0.0@<sha>)

限制:

  • 单文件 ≤ 50 MB
  • 不支持 .exe / .dmg / .pkg
  • 部分仓库结构异常时解析路径错

五、方案 4:ghfast.top 通用前缀

ghfast 同时支持 raw / Release / clone:

原:https://raw.githubusercontent.com/owner/repo/main/file
改:https://ghfast.top/https://raw.githubusercontent.com/owner/repo/main/file

不需要拆解 URL 结构,只在前面加前缀。脚本里最容易实现:

prefix="https://ghfast.top/"
url="https://raw.githubusercontent.com/owner/repo/main/install.sh"
curl -sSL "${prefix}${url}" | bash

六、方案 5:GitHub520 hosts

GitHub520 项目自动收集可用的 GitHub 系列 IP 并维护 hosts。

订阅 URL:https://raw.hellogithub.com/hosts(注意这本身就是 raw,先用方案 1-4 之一拿到 hosts 内容,再写入)

# macOS / Linux
sudo curl -fsSL https://gh-proxy.com/https://raw.githubusercontent.com/521xueweihan/GitHub520/main/hosts -o /tmp/hosts-github
# 把内容追加到 /etc/hosts(用 SwitchHosts 管理更省心)

注意:hosts 只对直连流量生效,挂了系统代理就被代理接管。

七、典型场景与推荐

场景推荐备注
`curl xxxbash` 安装脚本方案 4(ghfast 前缀)
拉规则集到 Clash / Mihomorule-provider URL 走原域 + 客户端挂代理不要固化镜像 URL
网页 / 浏览器看 raw 文件方案 5(hosts)不影响其他流量
前端项目引用 raw 资源方案 3(jsDelivr)CDN 加 cache
大文件(> 50 MB,如 LLM weights)方案 1 或 4jsDelivr 不行
自动化脚本方案 4 + ghproxy.link 公示备用域主域挂自动切

八、curl | bash 安装脚本的注意事项

很多开源工具的安装文档是:

curl -sSL https://raw.githubusercontent.com/owner/repo/main/install.sh | bash

国内直接跑常常超时。改写:

# 方案 A:加 ghfast 前缀
curl -sSL https://ghfast.top/https://raw.githubusercontent.com/owner/repo/main/install.sh | bash

# 方案 B:替换为 staticdn
curl -sSL https://raw.staticdn.net/owner/repo/main/install.sh | bash

注意:install.sh 内部如果又 curl 拉其他 raw 资源,需要这个脚本本身支持 mirror 环境变量(很多脚本不支持)。这种情况下:把脚本先下到本地,手动改路径,再执行。

九、长期方案:走稳定线路

公益镜像有三个不可控:域名变更、限速、停服。重度依赖 raw 资源(规则集订阅、CI 脚本、配置同步)的场景,长期更稳的做法是接一条兼容 Clash / Singbox / V2Ray 的订阅,把 raw.githubusercontent.com 列为代理走,所有 curl/wget/rule-provider 直接走代理,不依赖镜像方运维节奏。

十、避坑

  • 一些反代会缓存内容,你拉的可能是几小时前的版本 — 配置文件类用 ?t=$(date) 强制刷新
  • jsDelivr 的 @latest 不等同于 @main(latest 看 git tag,main 看分支)
  • 不要在反代 URL 里夹 token(理论上反代方能看到)
  • raw 文件最大行长度限制(GitHub 网页 ~10 MB),拉大文件用 Release

来源与时间戳

最后核对时间:2026-05-20。镜像域名随时变化,请以当前可用为准。