跳转到内容

GitHub 加速

未匹配 /v2/token/api 等路由的请求,由 GitHub 代理处理器接管。使用时在完整原始 URL 前加上 HubProxy 域名;匹配支持的 URL 类型后,处理器还原地址并代理到 GitHub、Hugging Face 等上游,不匹配则返回「无效输入」。

在原始 URL 前加上 HubProxy 域名,支持两种写法。

Terminal window
# Release 下载
curl -L -O "https://example.com/https://github.com/owner/repo/releases/download/v1.0.0/app.tar.gz"
# Git Clone
git clone https://example.com/https://github.com/owner/repo.git
# API
curl "https://example.com/https://api.github.com/repos/owner/repo/releases/latest"

配置 url.<base>.insteadOf 后,所有 https://github.com/ 开头的 clone/fetch 会自动走 HubProxy,无需每次手动改 URL:

Terminal window
git config --global url."https://example.com/https://github.com/".insteadOf "https://github.com/"

之后可直接:

Terminal window
git clone https://github.com/owner/repo.git
# 实际请求 https://example.com/https://github.com/owner/repo.git

取消配置:

Terminal window
git config --global --unset url.https://example.com/https://github.com/.insteadOf

HubProxy 会自动补全协议头:

Terminal window
curl -L -O "https://example.com/github.com/owner/repo/releases/download/v1.0.0/app.tar.gz"
类型 匹配路径示例
Release / Archive github.com/{owner}/{repo}/releases/.../archive/...
Raw / Blob github.com/{owner}/{repo}/raw/.../blob/ 自动转为 /raw/
Git 协议 github.com/{owner}/{repo}/info/.../git-...
Raw 域名 raw.githubusercontent.com/...raw.github.com/...
API api.github.com/repos/{owner}/{repo}/...
Gist gist.github.com/...gist.githubusercontent.com/...
Hugging Face huggingface.co/...cdn-lfs.hf.co/...
GitHub Assets github.githubassets.com/...opengraph.githubassets.com/...

HubProxy 可自动改写 .sh / .ps1 安装脚本中的 GitHub URL(脚本最大 10MB)。反代部署时需正确设置 X-Forwarded-Host,详见 反向代理配置

限制 说明
网页内容 text/htmlapplication/xml 等网页类型会被拒绝(403),不能用来加速 GitHub 网页浏览
文件大小 [server].fileSize 控制单文件上限,默认 2GB
仓库访问 [access].whiteList / blackList 限制可代理的 GitHub 仓库与 Hugging Face 资源

Release 等大文件支持 wget -c 断点续传,见 传输特性

[server]
fileSize = 2147483648
[access]
whiteList = ["trusted-org/*"]
blackList = ["*/malicious-repo"]