21
2023
11
00:43:30

关于Github加速方法总结



推荐点击下面图片,通过本站淘宝优惠价购买:

image.png

前言

最近网站大部分图片访问变慢, 原因出在jsdelivr加速失效, 为此我更换了CDN域名, 顺带总结一下github加速小技巧

GitHub访问加速

1. 使用镜像访问

这相当于是克隆版的 GitHub , 网站的内容和 GitHub 是完整同步, 可以在这个网站里面进行下载克隆等操作, 镜像地址如下:

使用示范:

1
2
3
4
5
https://github.com/typecho/typecho

可以改成

https://hub.fastgit.xyz/typecho/typecho

2.修改Host文件加速

首先需要获取对应域名实际ip地址, 可以通过以下网站查询:

image-20220707154831063

需要查询的地址有:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 基本地址
'github.com',
'gist.github.com',
'assets-cdn.github.com',
'raw.githubusercontent.com',
'gist.githubusercontent.com',
'cloud.githubusercontent.com',
'camo.githubusercontent.com',
'avatars0.githubusercontent.com',
'avatars1.githubusercontent.com',
'avatars2.githubusercontent.com',
'avatars3.githubusercontent.com',
'avatars4.githubusercontent.com',
'avatars5.githubusercontent.com',
'avatars6.githubusercontent.com',
'avatars7.githubusercontent.com',
'avatars8.githubusercontent.com',
'avatars.githubusercontent.com',
'github.githubassets.com',
'user-images.githubusercontent.com',
'codeload.github.com',
'favicons.githubusercontent.com',
'api.github.com'

一个一个查询太过麻烦, 可以使用python脚本快速批量获取, 代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
# coding:utf-8

import socket

def output_hosts():
   domains = ['github.com',
               'gist.github.com',
               'assets-cdn.github.com',
               'raw.githubusercontent.com',
               'gist.githubusercontent.com',
               'cloud.githubusercontent.com',
               'camo.githubusercontent.com',
               'avatars0.githubusercontent.com',
               'avatars1.githubusercontent.com',
               'avatars2.githubusercontent.com',
               'avatars3.githubusercontent.com',
               'avatars4.githubusercontent.com',
               'avatars5.githubusercontent.com',
               'avatars6.githubusercontent.com',
               'avatars7.githubusercontent.com',
               'avatars8.githubusercontent.com',
               'avatars.githubusercontent.com',
               'github.githubassets.com',
               'user-images.githubusercontent.com',
               'codeload.github.com',
               'favicons.githubusercontent.com',
               'api.github.com'
               ]
   
   with open('hosts.txt', 'w') as f:
       f.write('```\n')
       f.write('# GitHub Start \n')
       for domain in domains:
           print('Querying ip for domain %s'%domain)
           ip = socket.gethostbyname(domain)
           print(ip)
           f.write('%s %s\n'%(ip, domain))
       f.write('# GitHub End \n')
       f.write('```\n')
       
       
   
if __name__ == '__main__':
   output_hosts()

执行脚本后, 得到如下结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# GitHub Start 
140.82.121.3  github.com
140.82.121.3  gist.github.com
185.199.110.153 assets-cdn.github.com
185.199.108.133 raw.githubusercontent.com
185.199.111.133 gist.githubusercontent.com
185.199.110.133 cloud.githubusercontent.com
185.199.111.133 camo.githubusercontent.com
185.199.111.133 avatars0.githubusercontent.com
185.199.110.133 avatars1.githubusercontent.com
185.199.111.133 avatars2.githubusercontent.com
185.199.109.133 avatars3.githubusercontent.com
185.199.108.133 avatars4.githubusercontent.com
185.199.111.133 avatars5.githubusercontent.com
185.199.109.133 avatars6.githubusercontent.com
185.199.109.133 avatars7.githubusercontent.com
185.199.110.133 avatars8.githubusercontent.com
185.199.108.133 avatars.githubusercontent.com
185.199.111.154 github.githubassets.com
185.199.109.133 user-images.githubusercontent.com
140.82.112.9 codeload.github.com
185.199.110.133 favicons.githubusercontent.com
192.30.255.116 api.github.com
# GitHub End

将以上内容拷贝到系统Host文件中即可, 不同操作系统host文件所在路径不一样:

  1. Windows系统:修改C:\Windows\System32\drivers\etc\hosts文件

1
2
# 网络刷新
ipconfig /flushdns

  1. Linux系统:修改C:\Windows\System32\drivers\etc\hosts文件

    1
    2
    # 网络刷新
    systemctl restart network

仓库Clone下载加速

1. 将仓库克隆到Gitee

image-20220707151023271

2.使用Fast-GitHub浏览器插件

Fast-GitHub

image-20220707151433012

3.第三方网站解析加速

Toolwa

image-20220707151746721

gh-proxy

image-20220707152513916

Ghproxy

image-20220707155957192

image-20220707160024075

Raw资源加速

1. 使用fastgit

raw.githubusercontent.com替换成raw.staticdn.net或者raw.gitmirror.com

使用示例

实际上fastgit功能很丰富, 几乎囊括了github所有. 具体如下表:

反代列表

站源地址缓存
github.comhub.fastgit.xyz
raw.githubusercontent.comraw.staticdn.net
github.githubassets.comassets.fastgit.org
customer-stories-feed.github.comcustomer-stories-feed.fastgit.org480 分钟
Github Downloaddownload.fastgit.org480 分钟
GitHub Archivearchive.fastgit.org

fastgit官网

2.使用ghproxy

https://raw.githubusercontent.com地址前面添加https://ghproxy.com/

比如:

1
https://ghproxy.com/https://raw.githubusercontent.com/stilleshan/ServerStatus/master/Dockerfile


本文链接:http://www.hqyman.cn/post/4571.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:





休息一下,本站随机推荐观看栏目:


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

您的IP地址是: