如何解决GitHub图片加载不出来问题

1、问题描述

不少时候,咱们打开GitHub查看别人的项目时,会有图片加载不出来的状况,甚至包括用户的头像。以下面两幅图:php

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=git1.png watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=git2.png

此时打开控制台,甚至会看到一大波的错误:git

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=git3.png

主要思路就是使用本地hosts文件对网站进行域名解析,通常的DNS问题均可以经过修改hosts文件来解决,github的CDN域名被污染问题也不例外,一样能够经过修改hosts文件解决,将域名解析直接指向IP地址来绕过DNS的解析,以此解决污染问题。github

因此其实不论是windows下仍是Mac下解决的思路都是同样的,都是为了找到hosts文件,而后添上github的域名IP映射。windows

另外关于查询域名的对应IP映射能够到点击这里:https://www.ipaddress.com/编辑器

2、windows如何解决?

由于博主用的一直都是Mac,因此这里偷个懒,来个传送门:ide

【最新】解决Github网页上图片显示失败的问题3、Mac如何解决?网站

这里详细的记录下本身在Mac下是如何解决这个问题的。其实以前解决过一次,不事后来换了一次系统,配置文件又变更了,因此此次也是写篇文章总结一下。3d

1. 查找并打开hosts文件

按开头介绍的,解决的关键就是要找到hosts这个文件。code

打开达访,而后使用快速查找快捷键:cdn

Shift + Command + G

输入:

(我电脑中的这个文件是放在这个目录下的,可是我不是很肯定大家的是否是也是)

private/etc/

回车,进入这个文件夹中,能够找到hosts这个文件。

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=git4.png

若是你不肯定本身的host文件在哪里,你能够这样作:

1、打开终端

Command + 空格

输入terminal并回车

2、打开hosts文件

在终端中输入:

$ open /etc/hosts

并回车,此时会打开hosts文件。

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=git5.png

2. 修改etc文件夹权限

如上面那种图所示,你打开的hosts文件不必定可以编辑,也就是在文件名的边上显示的是已锁定。

这时候咱们须要修改一下这个文件夹的权限,也就是etc文件夹的权限。

1、

首先进入private文件夹下,并右键etc文件夹,点击显示简介。

2、

解锁hosts,点击右下脚的解锁按钮:

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=git6.png

3、

添加修改权限,我这里是将Admin和lindaidai都添加了进去,而且权限设置为读与写。

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=git7.png

通过上面几步,你再次打开hosts文件就能够进行编辑了。

3. 给hosts中添加github的IP地址

将如下配置添加到你的hosts文件中。

(hosts文件能够用任意的文本编辑器打开,例如我直接用的Mac自带的文本编辑)

# GitHub Start
140.82.113.3      github.com
140.82.114.20     gist.github.com

151.101.184.133    assets-cdn.github.com
151.101.184.133    raw.githubusercontent.com
151.101.184.133    gist.githubusercontent.com
151.101.184.133    cloud.githubusercontent.com
151.101.184.133    camo.githubusercontent.com
151.101.184.133    avatars0.githubusercontent.com
199.232.68.133     avatars0.githubusercontent.com
199.232.28.133     avatars1.githubusercontent.com
151.101.184.133    avatars1.githubusercontent.com
151.101.184.133    avatars2.githubusercontent.com
199.232.28.133     avatars2.githubusercontent.com
151.101.184.133    avatars3.githubusercontent.com
199.232.68.133     avatars3.githubusercontent.com
151.101.184.133    avatars4.githubusercontent.com
199.232.68.133     avatars4.githubusercontent.com
151.101.184.133    avatars5.githubusercontent.com
199.232.68.133     avatars5.githubusercontent.com
151.101.184.133    avatars6.githubusercontent.com
199.232.68.133     avatars6.githubusercontent.com
151.101.184.133    avatars7.githubusercontent.com
199.232.68.133     avatars7.githubusercontent.com
151.101.184.133    avatars8.githubusercontent.com
199.232.68.133     avatars8.githubusercontent.com

# GitHub End

以下图:

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

4、解决成功效果

保存成功上诉文件后,让咱们从新打开github再来看看吧。

good boy~ 完美解决:

watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=

相关文章
相关标签/搜索