前言
这个博客自从春节开始就没有更新过,不知不觉就到了大一结束的暑假了,今天突然有兴趣看一看自己的博客,改一改主题,加一加插件,结果刚想把博客从Github clone到本地1
git clone https://github.com/00why00/00why00.github.io.git
clone速度从17Kib/s慢慢变成3Kib/s
到最后,结果显示1
fatal: unable to access 'https://github.com/00why00/00why00.github.io.git': Proxy CONNECT aborted
检查自己的ssr,改成全局模式,仍然不行,遂Google
原因
暂时不明
经实验发现如下几个特点:
1、ShadowSocksR 这类工具尽管开启了全局代理,但是 cmd 里依旧无法下载成功。
2、这种全局代理只针对使用IE代理的程序才全局,不是像VPN那样的全局。当然也更不支持PAC模式。
解决办法
经过对大量他人博客的查看与思考,经过无数次失败之后,我终于总结出来了正确的方法
让 cmd 走代理的方法
在 cmd 中执行以下命令1
set ALL_PROXY=socks5://127.0.0.1:1080
1、因为Shadowsocks是一种基于Socks5代理方式的加密传输协议(见Wiki),所以必须为sock5而不是某些博客所说的http。
2、因为 ssr 代理端口为1080,所以其端口号不应设置为某些博客所说的8080等。
3、如果你的代理服务器要求用户名和密码的话,那么还需要:1
2set http_proxy_user=
set http_proxy_pass=
设置完成后,就可以在 cmd 下正常使用网络了。
让 git 走代理的方法
同理,在 git bush 中执行以下命令1
2git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080
如果需要用户名密码的话,则设置:1
2git config –global http.proxy http://user:password@socks5://127.0.0.1:1080
git config –global https.proxy http://user:password@socks5://127.0.0.1:1080
其中 user 和 password 分别为你的用户名和密码。
设置完成后,可以通过如下命令来查看设置是否生效:1
git config –get –global http.proxy
如果某一天你不喜欢她了,需要删除代理设置,那么可以使用:1
2git config --global (或 --system 或 --local) --unset http.proxy
git config --global (或 --system 或 --local) --unset https.proxy
来删除设置。
让 powershell 走代理的方法
从 Microsoft 的脚本中心下载的脚本,未经实验,请谨慎使用。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
46
47
48
49
50
51
52
53
54
55
56
57<#
.Synopsis
This function will set the proxy settings provided as input to the cmdlet.
.Description
This function will set the proxy server and (optinal) Automatic configuration script.
.Parameter ProxyServer
This parameter is set as the proxy for the system.
Data from. This parameter is Mandatory
.Example
Setting proxy information
Set-InternetProxy -proxy "proxy:7890"
.Example
Setting proxy information and (optinal) Automatic Configuration Script
Set-InternetProxy -proxy "proxy:7890" -acs "http://proxy:7892"
#>
Function Set-InternetProxy
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$True,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[String[]]$Proxy,
[Parameter(Mandatory=$False,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[AllowEmptyString()]
[String[]]$acs
)
Begin
{
$regKey="HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
}
Process
{
Set-ItemProperty -path $regKey ProxyEnable -value 1
Set-ItemProperty -path $regKey ProxyServer -value $proxy
if($acs)
{
Set-ItemProperty -path $regKey AutoConfigURL -Value $acs
}
}
End
{
Write-Output "Proxy is now enabled"
Write-Output "Proxy Server : $proxy"
if ($acs)
{
Write-Output "Automatic Configuration Script : $acs"
}
else
{
Write-Output "Automatic Configuration Script : Not Defined"
}
}
}
将上面的代码复制下来并保存为Set-InternetProxy.ps1即可。
结语
有些同学可能使用的是 Git 的客户端,比如我现在正在使用的 Github Desktop ,里面可能并没有代理设置的选项,不过别着急,这些客户端一般在底层都是调用的命令行工具,所以同样按照上述步骤进行设置即可。并在如下图选择你要使用的命令行工具
最后看到 clone 的速度从10Kib/s变成了1Mib/s,是不是开心极了 :)