最近在访问GitHub时发现所有涉及到图片都加载失败,使人感觉极度不适;不将就是发现的源动力;有了之前《WordPress网站访问慢解决方案(超详细图文教程)》经验这次解决起来就顺利许多,下面是解决方案。
优化前:
- 所有图片类型文件加载失败
优化后:
- 所有图片类型文件正常加载
问题(访问github,头像等图片加载失败)
定位问题(图片资源域名访问不通)
在cmd中 通过ping命令检查网络是通的,结果如下:
//check头像资源域名
ping avatars.githubusercontent.com
正在 Ping github.map.fastly.net [151.101.228.133] 具有 32 字节的数据:
来自 151.101.228.133 的回复: 字节=32 时间=175ms TTL=48
来自 151.101.228.133 的回复: 字节=32 时间=154ms TTL=48
来自 151.101.228.133 的回复: 字节=32 时间=154ms TTL=48
来自 151.101.228.133 的回复: 字节=32 时间=153ms TTL=48
可以看出是解析DNS出问题如下:
域名 | 现在DNS解析对应ip | 实际应该对应ip |
---|---|---|
avatars.githubusercontent.com | 151.101.228.133 | 199.232.96.133 |
解决步骤
在本机hosts(windows的hosts文件目录 C:\Windows\System32\drivers\etc\hosts)文件中增加头像域名和正确ip映射关系并保存
199.232.96.133 avatars.githubusercontent.com
在cmd中执行命令刷新本机DNS缓存
ipconfig /flushdns
进行验证,再次刷新github,发现头像可以正常加载,一下心情美丽许多
当浏览项目时,发现有些项目中的图片还是加载失败
项目中的图片URL和头像URL对比;发现两者URL的二级域名一致,但是三级域名不同,又浏览一些项目发现每个项目中的文件地址中的三级域名都有可能不同
头像域名 | 项目文件域名1 | 项目文件域名2 | 项目文件域名N |
---|---|---|---|
avatars.githubusercontent.com | camo.githubusercontent.com | raw.githubusercontent.com | … |
第一直觉解决方案是:hosts中通过 * 全匹配二级域名去解决如下,不过实验以及查资料发现不hosts文件不支持这种规则
//在hosts中用通配符来匹配二级域名下三级域名---不支持
199.232.96.133 *.githubusercontent.com
//在hosts中这样配置 只对githubusercontent.com 而对 avatars.githubusercontent.com 这些三级域名不生效
199.232.96.133 githubusercontent.com
程序猿的第一反应既然通配符这种形式行不通那就进行遍历;先在此贴出最终遍历后的hosts文件,大家可以直接用;下面会讲解如何获得内容
199.232.96.133 scoopraw.githubusercontent.com
199.232.96.133 avators.githubusercontent.com
199.232.96.133 releases.githubusercontent.com
199.232.96.133 2021-01-29-----2021-01-31github-releases.githubusercontent.com
199.232.96.133 github-releases.githubusercontent.com
199.232.96.133 avaters.githubusercontent.com
199.232.96.133 ocame.githubusercontent.com
199.232.96.133 github.comraw.githubusercontent.com
199.232.96.133 vatars5.githubusercontent.com
199.232.96.133 cano.githubusercontent.com
199.232.96.133 vatars3.githubusercontent.com
199.232.96.133 usr-image.githubusercontent.com
199.232.96.133 war.githubusercontent.com
199.232.96.133 avatar6.githubusercontent.com
199.232.96.133 avatar7.githubusercontent.com
199.232.96.133 clound.githubusercontent.com
199.232.96.133 r-images.githubusercontent.com
199.232.96.133 2017-12-14-----2020-12-22raw.githubusercontent.com
199.232.96.133 raww.githubusercontent.com
199.232.96.133 avastar0.githubusercontent.com
199.232.96.133 ccraw.githubusercontent.com
199.232.96.133 1h3.githubusercontent.com
199.232.96.133 came.githubusercontent.com
199.232.96.133 marketplace-images.githubusercontent.com
199.232.96.133 desktep.githubusercontent.com
199.232.96.133 eaw.githubusercontent.com
199.232.96.133 rawxx.githubusercontent.com
199.232.96.133 user.githubusercontent.com
199.232.96.133 git.githubusercontent.com
199.232.96.133 giraw.githubusercontent.com
199.232.96.133 avatars56.githubusercontent.com
199.232.96.133 image.githubusercontent.com
199.232.96.133 windowsraw.githubusercontent.com
199.232.96.133 ist.githubusercontent.com
199.232.96.133 raw.githubraw.githubusercontent.com
199.232.96.133 images.githubusercontent.com
199.232.96.133 avatar3.githubusercontent.com
199.232.96.133 avatar5.githubusercontent.com
199.232.96.133 avatar4.githubusercontent.com
199.232.96.133 avatar9.githubusercontent.com
199.232.96.133 avatars10000000000000000000000000000.githubusercontent.com
199.232.96.133 avatars40.githubusercontent.com
199.232.96.133 avatars10000000000000000000000000000000000000000.githubusercontent.com
199.232.96.133 avatars900.githubusercontent.com
199.232.96.133 avatars10000.githubusercontent.com
199.232.96.133 avatars1000.githubusercontent.com
199.232.96.133 avatars80.githubusercontent.com
199.232.96.133 avatars100000000.githubusercontent.com
199.232.96.133 avatars500.githubusercontent.com
199.232.96.133 codeload.githubusercontent.com
199.232.96.133 house.githubusercontent.com
199.232.96.133 httpsraw.githubusercontent.com
199.232.96.133 gaw.githubusercontent.com
199.232.96.133 user-image.githubusercontent.com
199.232.96.133 actions.githubusercontent.com
199.232.96.133 ser-images.githubusercontent.com
199.232.96.133 awe.githubusercontent.com
199.232.96.133 rawraw.githubusercontent.com
199.232.96.133 w.githubusercontent.com
199.232.96.133 rqw.githubusercontent.com
199.232.96.133 coma.githubusercontent.com
199.232.96.133 raws.githubusercontent.com
199.232.96.133 rapid.githubusercontent.com
199.232.96.133 avatar.githubusercontent.com
199.232.96.133 www.avatars0.githubusercontent.com
199.232.96.133 assets-cdn.githubusercontent.com
199.232.96.133 cone.githubusercontent.com
199.232.96.133 favicons.githubusercontent.com
199.232.96.133 pkg.githubusercontent.com
199.232.96.133 rwa.githubusercontent.com
199.232.96.133 raw.raw.githubusercontent.com
199.232.96.133 avatar0.githubusercontent.com
199.232.96.133 avatar2.githubusercontent.com
199.232.96.133 avatar1.githubusercontent.com
199.232.96.133 1raw.githubusercontent.com
199.232.96.133 row.githubusercontent.com
199.232.96.133 github.githubusercontent.com
199.232.96.133 cam.githubusercontent.com
199.232.96.133 api.githubusercontent.com
199.232.96.133 wwwcamo.githubusercontent.com
199.232.96.133 www.camo.githubusercontent.com
199.232.96.133 avatars99.githubusercontent.com
199.232.96.133 avatars19.githubusercontent.com
199.232.96.133 avatars16.githubusercontent.com
199.232.96.133 avatars13.githubusercontent.com
199.232.96.133 avatars12.githubusercontent.com
199.232.96.133 avatars20.githubusercontent.com
199.232.96.133 avatars17.githubusercontent.com
199.232.96.133 avatars11.githubusercontent.com
199.232.96.133 avatars15.githubusercontent.com
199.232.96.133 avatars14.githubusercontent.com
199.232.96.133 avatars18.githubusercontent.com
199.232.96.133 avatars800.githubusercontent.com
199.232.96.133 marketplace-screenshots.githubusercontent.com
199.232.96.133 repository-images.githubusercontent.com
199.232.96.133 gits.githubusercontent.com
199.232.96.133 rraw.githubusercontent.com
199.232.96.133 avatars.githubusercontent.com
199.232.96.133 aw.githubusercontent.com
199.232.96.133 avatars100.githubusercontent.com
199.232.96.133 pipelines.actions.githubusercontent.com
199.232.96.133 user-images.githubusercontent.com
199.232.96.133 media.githubusercontent.com
199.232.96.133 vatars0.githubusercontent.com
199.232.96.133 render.githubusercontent.com
199.232.96.133 www.raw.githubusercontent.com
199.232.96.133 avatars8.githubusercontent.com
199.232.96.133 avatars7.githubusercontent.com
199.232.96.133 avatars9.githubusercontent.com
199.232.96.133 avatars6.githubusercontent.com
199.232.96.133 avatars5.githubusercontent.com
199.232.96.133 avatars10.githubusercontent.com
199.232.96.133 avatars4.githubusercontent.com
199.232.96.133 gist.githubusercontent.com
199.232.96.133 www.githubusercontent.com
199.232.96.133 desktop.githubusercontent.com
199.232.96.133 avatars3.githubusercontent.com
199.232.96.133 avatars0.githubusercontent.com
199.232.96.133 avatars1.githubusercontent.com
199.232.96.133 cloud.githubusercontent.com
199.232.96.133 camo.githubusercontent.com
199.232.96.133 githubusercontent.com
199.232.96.133 avatars2.githubusercontent.com
199.232.96.133 raw.githubusercontent.com
将这个全的内容放入到hosts文件中
通过cmd命令(ipconfig /flushdns)重新刷新本机DNS
获取三级域名及形成符合hosts文件格式文件内容
需要知道GitHub资源文件二级域名(githubusercontent.com)都有哪些三级域名
随机抽查几个三级域名去 域名对应ip查询( https://www.ipaddress.com) 发现对应ip都是199.232.96.133
这么多二级域名怎么给转换成hosts文件格式那?肯定不能一个一个粘贴
//hosts格式:ip 三级域名
199.232.96.133 scoopraw.githubusercontent.com
199.232.96.133 avators.githubusercontent.com
·····
想到之前用的一个八爪鱼采集器可以获取网页数据的软件,可以将这些三级域名数据爬取到excel中