> 文档中心 > 如何解决上传到github上的图片显示不出来的问题

如何解决上传到github上的图片显示不出来的问题

你有没有遇到上传github仓库的图片,显示不出来的情况,或者是仓库的README.md文件,插入的图片总是莫名其妙的无法显示,而且重新编辑也没什么卵用。

于是我们可以使用chrome或是edge浏览器,F12打开开发者工具,你会发现获取图片报错的提示:

Failed to load resource: net::ERR_CERT_COMMON_NAME_INVALID

经过查阅了解的资料,综合起来,出现这样的报错提示,是因为我们使用一个错误的域名访问了某个节点的https资源导致的。原因大致是

1.dns污染
2.host设置错误
3.官方更新了dns,但是dns缓存没有被更新,导致错误解析。

所以,我们需要找到获取失败的图片地址,在控制台获取资源失败的提示里查看,图片来源的域名:

raw.githubusercontent.com

打开一个域名解析网站:①https://ping.eu/nslookup

                                        ②https://www.ipaddress.com/

 获取图片域名对应的ip地址:

raw.githubusercontent.com has address 185.199.111.133raw.githubusercontent.com has address 185.199.110.133raw.githubusercontent.com has address 185.199.108.133raw.githubusercontent.com has address 185.199.109.133raw.githubusercontent.com has IPv6 address 2606:50c0:8003::154raw.githubusercontent.com has IPv6 address 2606:50c0:8000::154raw.githubusercontent.com has IPv6 address 2606:50c0:8001::154raw.githubusercontent.com has IPv6 address 2606:50c0:8002::154

所以,我们需要把以上IP域名映射起来,如何映射呢? 

使用记事本或是任意IDE工具打开本机的hosts文件:C:\Windows\System32\drivers\etc\hosts

把获取到的域名和ip地址加入到hosts文件中,保存即可,如下:

# GitHub Start 140.82.113.3      github.com140.82.114.20     gist.github.com151.101.184.133    assets-cdn.github.com151.101.184.133    raw.githubusercontent.com151.101.184.133    gist.githubusercontent.com151.101.184.133    cloud.githubusercontent.com151.101.184.133    camo.githubusercontent.com151.101.184.133    avatars0.githubusercontent.com199.232.68.133     avatars0.githubusercontent.com199.232.28.133     avatars1.githubusercontent.com151.101.184.133    avatars1.githubusercontent.com151.101.184.133    avatars2.githubusercontent.com199.232.28.133     avatars2.githubusercontent.com151.101.184.133    avatars3.githubusercontent.com199.232.68.133     avatars3.githubusercontent.com151.101.184.133    avatars4.githubusercontent.com199.232.68.133     avatars4.githubusercontent.com151.101.184.133    avatars5.githubusercontent.com199.232.68.133     avatars5.githubusercontent.com151.101.184.133    avatars6.githubusercontent.com199.232.68.133     avatars6.githubusercontent.com151.101.184.133    avatars7.githubusercontent.com199.232.68.133     avatars7.githubusercontent.com151.101.184.133    avatars8.githubusercontent.com199.232.68.133     avatars8.githubusercontent.com185.199.111.133    raw.githubusercontent.com 185.199.110.133    raw.githubusercontent.com 185.199.108.133    raw.githubusercontent.com 185.199.109.133    raw.githubusercontent.com # GitHub End

以上ip是github当前使用的最新的ip地址,可能之后还会发生变更,如果遇到图片不能显示了,大家可依据上述方法及时更新ip配置host文件即可。

补充点番外知识:

遇到网络异常,可能是DNS缓存的问题,这时你可以使用ipconfig/flush命令对本地DNS缓存进行一次刷新即可,如下步骤:👇

使用快捷键windows徽标开始+R打开命令行窗口👉输入:cmd,按回车键,
👉再输入: ipconfig /flushdns,👉按回车,执行命令,可以重建本地DNS缓存。

总结一下常用的几个操作dns的命令:👇

ipconfig /displaydns   # 可以显示dns缓存 ipconfig /flushdns   # 可以刷新DNS记录 ipconfig /renew    # 可以重新从DHCP服务器获得IP

​​​​​​​最后附上:修改后github图片显示的出来的效果🤳

👉你可能还想了解:如何解决GitHub仓库README文件插入图片后无法显示的问题​​​​​​​

如何解决上传到github上的图片显示不出来的问题 创作打卡挑战赛 如何解决上传到github上的图片显示不出来的问题 赢取流量/现金/CSDN周边激励大奖