简 述: 打开网站 GitHub 的时候,经常会遇到加载图片丢失,或者有的图片能够显示,又是不能显示出来;非要开全局代理才能所有头像、图片资源才能够显示出来。附上解决方案:强制指定域名走代理和修改 hosts 文件。

[TOC]


本文初发于 “偕臧的小站“,同步转载于此。


背景:

💻: MacOS 10.14.6 📎 win10 2004版本 x64中,打开 github 或者相关网站的时候,经常图片资源没有加载出来,看到的效果就是用户头像缺失。


解决方案:

定位问题:

  1. 在浏览器打开 github 网站,右键“检查(Ctrl + Shift + I)”;

  2. 进入 “网络-全部-标头”, 然后刷新此页面,再次加载本网页

  3. 查看获取文件失败的的报文的请求链接。发现是 githubusercontent.com 域名, 而非也是 “github.com” 域名

  4. 在 代理软件里添加 ||githubusercontent.com,其中 || 表示匹配该域名的所有子域名,点击保存

  5. 再次刷新网页,即可看到头像都加载出来了


补充:

有时候, 经过上面的操作后,大部分图片资源都加载出来了,但是还有少部分的头像没有被加载出来。 这就狠狠狠狠。。。。。

原因: 本土网络环境emmmm, 估计是大概率被 DNS 给污染了, 这里就需要手动修改 hosts 了

解决:

  • 查询域名对应的真实 IP
  • 将其追加到 hosts文件中;

可在https://www.ipaddress.com/ 查询 raw.githubusercontent.com 的真实IP


这里附上已经查询好了的,更新于 2022-01-208 日,[其中 assets-cdn.github.com 有四个,若是第一个失败了,则会解析第二个,依次(但是没有负载均衡的效果)]:

# GitHub Start 
140.82.113.3 github.com
140.82.113.3 gist.github.com
185.199.108.153 assets-cdn.github.com
185.199.109.153 assets-cdn.github.com
185.199.110.153 assets-cdn.github.com
185.199.111.153 assets-cdn.github.com
185.199.108.153 raw.githubusercontent.com
185.199.109.153 raw.githubusercontent.com
185.199.110.153 raw.githubusercontent.com
185.199.111.153 raw.githubusercontent.com
185.199.108.133 gist.githubusercontent.com
185.199.109.133 gist.githubusercontent.com
185.199.110.133 gist.githubusercontent.com
185.199.111.133 gist.githubusercontent.com
185.199.108.133 cloud.githubusercontent.com 
185.199.109.133 cloud.githubusercontent.com 
185.199.110.133 cloud.githubusercontent.com 
185.199.111.133 cloud.githubusercontent.com 
185.199.108.133 camo.githubusercontent.com
185.199.109.133 camo.githubusercontent.com
185.199.110.133 camo.githubusercontent.com
185.199.111.133 camo.githubusercontent.com
185.199.108.133 avatars0.githubusercontent.com
185.199.108.133 avatars1.githubusercontent.com
185.199.108.133 avatars2.githubusercontent.com
185.199.108.133 avatars3.githubusercontent.com
185.199.108.133 avatars4.githubusercontent.com
185.199.108.133 avatars5.githubusercontent.com
185.199.108.133 avatars6.githubusercontent.com
185.199.108.133 avatars7.githubusercontent.com
185.199.108.133 avatars8.githubusercontent.com
# GitHub End
  • hosts 文件所在目录:
    • [win:] C:\Windows\System32\drivers\etc\hosts
    • [Mac:] /etc/hosts
    • [Linux:] /etc/hosts

OK, 到这里就是大功告成了,再怎么打开github网站,都不会有网页图片资源缺失的情况出现