解決GitHub網頁githubusercontent地址無法訪問問題

去年年底開始GitHub裏面的用戶頭像無法顯示,頁面也加載緩慢,這下快樂的日子可能一去不復返了,我們需要把相關域名加加速了。

GitHub裏面圖片都在githubusercontent.com域名上,我們只需要在hosts裏面加上相關地址即可。如果你有代理,把域名加入到許可名單也可以的。

這裏我們介紹hosts方式是如何使用的,把以下內容添加到hosts文件中。

1. hosts內容

# 20201230日更新

# 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是通過dns查詢工具查詢得到的,你應當選擇的是延時相對較小且比較穩定的ip。

如果發現不起作用,或者速度不理想,參考查找域名IP

2. 如何修改

這裏推薦使用 SwitchHosts! 配置hosts,操作很簡單,支持跨平臺。

複製前面的hosts內容到軟件裏配置即可,相關介紹參考下面文章。

SwitchHosts! 還能這樣管理hosts,後悔沒早點用

2.1 Windows

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

將前文內容追加到hosts,然後刷新DNS緩存:

ipconfig /flushdns

2.2 Mac

hosts文件位置:/etc/hosts

Mac系統下修改需要按照如下方式:

1:首先,打開(訪達)Finder。

2:使用組合鍵Shift+Command+G打開"前往文件夾",在輸入框輸入/etc/hosts

3:然後就會跳轉到hosts文件位置。

複製hosts文件到桌面上,鼠標右鍵點擊/右擊它,選擇「打開方式」—「文本編輯」,打開這個hosts文件,然後將你要修改的內容直接在裏面修改就好了。

然後把你修改好的hosts文件在複製回hosts文件的所在(文件夾下)路徑:/etc/hosts 之下替換原始的hosts文件就好了。

注意:如果彈出密碼輸入框,你需要輸入你當前電腦登錄賬號的密碼。

最後刷新下緩存:

sudo killall -HUP mDNSResponder

3. 查找域名IP

注:2020年12月30日我實際使用 IPAddress纔可以生效,前面兩個查詢站點獲取的 IP均無法使用,各位可以都嘗試下直到生效。

前面hosts裏面域名裏分爲兩類:

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

*.githubusercontent.com可以使用同一個IP,不需要每個單獨查詢。*.github.com未經測試,目前看是需要單獨查詢對應的IP

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章