不知道什么時(shí)候開(kāi)始氧枣,GitHub
里面的圖片也無(wú)法加載出來(lái),本來(lái)頁(yè)面也加載緩慢别垮,這下更是雪上加霜便监,好在還是有簡(jiǎn)單的方式加速GitHub
的訪問(wèn)。
通過(guò)設(shè)置hosts
就是一個(gè)低成本的方案碳想, GitHub
里面圖片都在githubusercontent.com
域名下烧董,我們只需要在hosts
里綁定域名和對(duì)應(yīng)的IP
。
1. hosts內(nèi)容
hosts
文件內(nèi)容如下:
# 2020年12月30日更新
# 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
如果發(fā)現(xiàn)沒(méi)有作用胧奔,或者速度不理想逊移,參考查找IP更新下對(duì)應(yīng)的IP
地址。
2. 如何修改 hosts
2.1 Windows
hosts文件位置:C:/windows/system32/drivers/etc/hosts
龙填。
將前文內(nèi)容追加到hosts
胳泉,然后刷新DNS
緩存:
ipconfig /flushdns
2.2 macOS
hosts文件位置:/etc/hosts
。
macOS
系統(tǒng)下修改需要按照如下方式:
1:首先岩遗,打開(kāi)(訪達(dá))Finder胶背。
2:使用組合鍵Shift+Command+G
打開(kāi)"前往文件夾",輸入框中輸入/etc/hosts
喘先。
3:然后就會(huì)跳轉(zhuǎn)到hosts
文件位置。
注意:如果你使用
VS Code
廷粒,可以直接用VS Code
修改和保存窘拯。
復(fù)制hosts
文件到桌面上红且,鼠標(biāo)右鍵右擊它,選擇「打開(kāi)方式」—「文本編輯」涤姊,打開(kāi)這個(gè)hosts
文件暇番,然后將你要修改的內(nèi)容直接在里面修改就好了。
然后把你修改好的hosts
文件替換掉:/etc/hosts
文件思喊。
注意:如果彈出密碼輸入框壁酬,你需要輸入你當(dāng)前電腦登錄賬號(hào)的密碼。
最后刷新緩存:
sudo killall -HUP mDNSResponder
<h2 id="fetch-dns">3. 查找IP</h2>
注:2020年12月30日我實(shí)際使用
IPAddress
才可以生效恨课,前面兩個(gè)查詢站點(diǎn)獲取的IP
均無(wú)法使用舆乔,各位可以都嘗試下直到生效。
前面hosts
里面域名里分為兩類:
- *.githubusercontent.com
- *.github.com
*.githubusercontent.com
可以使用同一個(gè)IP
剂公,不需要每個(gè)單獨(dú)查詢希俩。*.github.com
未經(jīng)測(cè)試,目前看是需要單獨(dú)查詢對(duì)應(yīng)的IP
纲辽。
其他方案
鏡像站點(diǎn)
這兩個(gè)網(wǎng)站是整站訪問(wèn)的替代品颜武,你可以瀏覽項(xiàng)目,也支持下載檢出拖吼。
但是不建議登陸自己的賬號(hào)鳞上,畢竟不是直接訪問(wèn)到原站。
文件下載
該方案利用Cloudflare Workers
對(duì) release
吊档、archive
以及項(xiàng)目文件進(jìn)行加速篙议,部署無(wú)需服務(wù)器。
如果對(duì)自建感興趣籍铁,可以訪問(wèn)gh-proxy涡上。
Raw加速
- https://7ed.net/gra
- jsDelivr
jsDelivr
不支持exe
文件下載,使用方法參考例子拒名。
地址格式如下吩愧,version
忽略則始終使用最新版本:
https://cdn.jsdelivr.net/gh/user/repo@version/file
舉個(gè)例子:
# 原始url
https://github.com/ineo6/homebrew-install/blob/master/install.sh
# 轉(zhuǎn)換結(jié)果
https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install.sh
關(guān)注公眾號(hào)“湖中劍”,獲得更多精彩文章增显。