解决GitHub网页githubusercontent地址无法访问问题

不知道什么时候开始,GitHub里面的图片也无法加载出来,本来页面也加载缓慢,这下更是雪上加霜,好在还是有简单的方式加速GitHub的访问。

通过设置hosts就是一个低成本的方案, GitHub里面图片都在githubusercontent.com域名下,我们只需要在hosts里绑定域名和对应的IP

插播广告,GitMaster是针对GitHub,Gitlab,Gitee的浏览器扩展,它能按照树形展示仓库的结构,同时支持文件下载,通知系统功能。

GitMaster 你的代码树浏览器助手
GitMaster是一款Chrome扩展,主要功能是在网页端查看git项目的代码树结构。 (更多…)
阅读1,960
评论 0

1. hosts内容

hosts文件内容如下:

# 2020年12月30日更新

# GitHub Start
52.74.223.119     github.com
52.74.223.119   gist.github.com
54.169.195.247   api.github.com
185.199.111.153   assets-cdn.github.com
199.232.96.133    raw.githubusercontent.com
199.232.96.133    gist.githubusercontent.com
199.232.96.133    cloud.githubusercontent.com
199.232.96.133   camo.githubusercontent.com
199.232.96.133   avatars0.githubusercontent.com
199.232.96.133    avatars1.githubusercontent.com
199.232.96.133   avatars2.githubusercontent.com
199.232.96.133    avatars3.githubusercontent.com
199.232.96.133    avatars4.githubusercontent.com
199.232.96.133    avatars5.githubusercontent.com
199.232.96.133    avatars6.githubusercontent.com
199.232.96.133    avatars7.githubusercontent.com
199.232.96.133    avatars8.githubusercontent.com
199.232.96.133  user-images.githubusercontent.com
185.199.109.154   github.githubassets.com
# GitHub End

如果发现没有作用,或者速度不理想,参考查找IP更新下对应的IP地址。

2. 如何修改 hosts

2.1 Windows

hosts文件位置:C:/windows/system32/drivers/etc/hosts

将前文内容追加到hosts,然后刷新DNS缓存:

ipconfig /flushdns

2.2 macOS

hosts文件位置:/etc/hosts

macOS系统下修改需要按照如下方式:

1:首先,打开(访达)Finder。
2:使用组合键Shift+Command+G打开"前往文件夹",输入框中输入/etc/hosts
3:然后就会跳转到hosts文件位置。

注意:如果你使用VS Code,可以直接用VS Code修改和保存。

复制hosts文件到桌面上,鼠标右键右击它,选择「打开方式」—「文本编辑」,打开这个hosts文件,然后将你要修改的内容直接在里面修改就好了。

然后把你修改好的hosts文件替换掉:/etc/hosts 文件。

注意:如果弹出密码输入框,你需要输入你当前电脑登录账号的密码。

最后刷新缓存:

sudo killall -HUP mDNSResponder

3. 查找IP

注:2020年12月30日我实际使用IPAddress才可以生效,前面两个查询站点获取的IP均无法使用,各位可以都尝试下直到生效。

前面hosts里面域名里分为两类:

  • *.githubusercontent.com
  • *.github.com

*.githubusercontent.com可以使用同一个IP,不需要每个单独查询。*.github.com未经测试,目前看是需要单独查询对应的IP

其他方案

镜像站点

这两个网站是整站访问的替代品,你可以浏览项目,也支持下载检出。

但是不建议登陆自己的账号,毕竟不是直接访问到原站。

文件下载

该方案利用Cloudflare Workersreleasearchive以及项目文件进行加速,部署无需服务器。

如果对自建感兴趣,可以访问gh-proxy

Raw加速

jsDelivr不支持exe文件下载,使用方法参考例子。

地址格式如下,version忽略则始终使用最新版本:

https://cdn.jsdelivr.net/gh/user/repo@version/file

举个例子:

# 原始url
https://github.com/ineo6/homebrew-install/blob/master/install.sh

# 转换结果
https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh

0 条评论