GitHub圖片加載不出來解決方案(超詳細圖文教程)
前言
最近在訪問GitHub時發現所有涉及到圖片都加載失敗,使人感覺極度不適;不將就是發現的源動力;有了之前《WordPress網站訪問慢解決方案(超詳細圖文教程)》經驗這次解決起來就順利許多,下面是解決方案,
優化前:
- 所有圖片型別檔案加載失敗
優化后:
- 所有圖片型別檔案正常加載
學完本教程你能得到什么
- 排查網站加載資源失敗解決思路
- 使用軟體獲取網頁資料進行格式化處理
- 一顆不斷探索的心
- 一套可實時可落地的解決問題的套路
解決方案流程圖
- 流程圖

問題&解決方案&驗證
-
問題(訪問github,頭像等圖片加載失敗)

-
定位問題(圖片資源域名訪問不通)
-
在google瀏覽器按F12,指定頭像,找到頭像url地址

-
在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 -
查詢域名映射ip對應關系網站 https://www.ipaddress.com

-
可以看出是決議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,發現頭像可以正常加載,一下心情美麗許多

-
當瀏覽專案時,發現有些專案中的圖片還是加載失敗
-
再次通過google瀏覽器F12定位圖片URL

-
專案中的圖片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)都有哪些三級域名
-
在一個通過二級域名查其含有三級域名網站進行查詢https://chaziyu.com 發現共有124條子域名

-
隨機抽查幾個三級域名去 域名對應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中
-
輸入需要爬取網頁地址

-
自動識別網頁

-
生成采集設定

-
進行資料采集

-
采集完成后匯出excel

-
-
在excel中洗掉無用列并將 子域名列124條資料粘貼到文本編輯器中(在此以Sublime為例)


-
在Sublime中進行列選擇在其前面增加統一的ip形成新的hosts檔案

-
總結
- 歡迎大家訪問我的GitHub并start
- 本人將持續不斷的在GitHub上輸出優秀成系列的代碼
CSDN認證博客專家
分布式
Spring
Redis
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/257420.html
標籤:其他
