Go to file
Zhicheng Zhang f96a5219dc support aws lambda and cloudfront 2025-10-28 21:29:00 +08:00
app
Dockerfile
LICENSE
README.md support aws lambda and cloudfront 2025-10-28 21:29:00 +08:00
entrypoint.sh
index.js support aws lambda and cloudfront 2025-10-28 21:29:00 +08:00

README.md

gh-proxy

简介

github release、archive以及项目文件的加速项目支持clone有Cloudflare Workers无服务器版本以及Python版本

演示

https://gh.api.99988866.xyz/

演示站为公共服务,如有大规模使用需求请自行部署,演示站有点不堪重负

imagea272c95887343279.png

当然也欢迎捐赠以支持作者

python版本和cf worker版本差异

  • python版本支持进行文件大小限制超过设定返回原地址 issue #8

  • python版本支持特定user/repo 封禁/白名单 以及passby issue #41

使用

直接在copy出来的url前加https://gh.api.99988866.xyz/即可

也可以直接访问在input输入

大量使用请自行部署,以上域名仅为演示使用。

访问私有仓库可以通过

git clone https://user:TOKEN@ghproxy.com/https://github.com/xxxx/xxxx #71

以下都是合法输入(仅示例,文件不存在):

cf worker版本部署

首页:https://workers.cloudflare.com

注册,登陆,Start building,取一个子域名,Create a Worker

复制 index.js 到左侧代码框,Save and deploy。如果正常,右侧应显示首页。

ASSET_URL是静态资源的url实际上就是现在显示出来的那个输入框单页面

PREFIX是前缀,默认(根路径情况为"/"如果自定义路由为example.com/gh/*请将PREFIX改为 '/gh/',注意,少一个杠都会错!

AWS Lambda@Edge 部署

CloudFront

  1. 前往 AWS CloudFront https://console.aws.amazon.com/cloudfront ,点击 Create distribution 。
  2. Step 1
    • 随便填一个 Distribution name点击 Next 。
  3. Step 2
    • 选择 Origin type 里面的 Other 。
    • 选项 Origin / Custom origin 填写 aws.amazon.com 。
    • 选项 Settings / Cache settings 选择 Customize cache settings 。
    • 选项 Allowed HTTP methods 选择 GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE 。
    • 选项 Cache policy 选择 Caching Disabled 。
    • 选项 Origin request policy 选择 AllViewer 。
    • 选项 Response headers policy 选择 Managed-CORS-with-preflight-and-SecurityHeadersPolicy 。
    • 点击 Next 。
  4. Step 3
    • 选择 Do not enable security protections ,点击 Next 。
  5. Step 4
    • 点击 Create Distribution 。
  6. 记录新建的 Distribution ID 。

Lambda - Code

  1. 前往 AWS Lambda https://console.aws.amazon.com/lambda ,点击 Create Function 。
  2. 输入名称,点击 Create Function 。
  3. 点击 Code 选项卡,复制 index.js 文件内容到 VSCode 在线编辑器中的 index.mjs 文件,将函数调用 addEventListener 注释掉。
  4. 点击 VSCode 在线编辑器左侧的 Deploy 。
  5. 点击 Configuration 选项卡,前往 Configuration 选项卡,点击 Edit修改 Timeout 为 0 min 10 sec 。

Lambda - Trigger

  1. 前往 AWS Lambda https://console.aws.amazon.com/lambda
  2. 点击 Function overview / Diagram 里面的 Add trigger 。
  3. 选择 CloudFront点击 Deploy to Lambda@Edge 。
  4. 在弹出的页面中:
    • Select an option 选择 Configure new CloudFront trigger 。
    • Distribution 选择刚刚新建的 Distribution ID 。
    • CloudFront event 选择 Viewer request 。
    • 勾选 Include body 和 Confirm 。
    • 点击 Deploy 。
  5. 如果提示权限问题,那么前往 Configuration 选项卡,点击 Edit 。
    • 将 Execution role 设为 Create a new role from AWS policy templates 。
    • 将 Policy templates 设为 Basic Lambda@Edge permissions (for CloudFront trigger) 。
    • 点击 Save 。

Python版本部署

Docker部署

docker run -d --name="gh-proxy-py" \
  -p 0.0.0.0:80:80 \
  --restart=always \
  hunsh/gh-proxy-py:latest

第一个80是你要暴露出去的端口

直接部署

安装依赖请使用python3

pip install flask requests

按需求修改app/main.py的前几项配置

注意: 可能需要在return Response前加两行

if 'Transfer-Encoding' in headers:
    headers.pop('Transfer-Encoding')

注意

python版本的机器如果无法正常访问github.io会启动报错请自行修改静态文件url

python版本默认走服务器2021.3.27更新)

Cloudflare Workers计费

overview 页面可参看使用情况。免费版每天有 10 万次免费请求并且有每分钟1000次请求的限制。

如果不够用,可升级到 $5 的高级版本,每月可用 1000 万次请求(超出部分 $0.5/百万次请求)。

Changelog

  • 2020.04.10 增加对raw.githubusercontent.com文件的支持
  • 2020.04.09 增加Python版本使用Flask
  • 2020.03.23 新增了clone的支持
  • 2020.03.22 初始版本

链接

我的博客

参考

jsproxy

捐赠

wx.png ali.png