0%

git通过lantern代理访问github

最近github可以使用ssh方式,https存在问题

git clone https://github.com/Valloric/YouCompleteMe.git                         
正克隆到 'YouCompleteMe'...
fatal: unable to access 'https://github.com/Valloric/YouCompleteMe.git/': Failed to connect to github.com port 443: 拒绝连接

修改为 SSH 方式可以解决问题 Changing a remote’s
URL

但是vim 插件安装会使用 https ,尝试使用代理来解决问题:

git config --global http.proxy 192.168.1.1:8083
git config --global http.proxy //查询
git config --global --unset http.proxy //取消

启动lantern并找到PAC文件

Jul 18 01:02:23.713 - 0m0s DEBUG flashlight: pac.go:155 Serving PAC file at
http://127.0.0.1:16823/proxy_on.pac

打开浏览器输入该url可以得到PAC文件,如下:

var bypassDomains = ['ss1.baidu.com', 'static.zhihu.com',
    'camo.githubusercontent.com', 'sugar.zhihu.com',
    'pagead2.googlesyndication.com', 'ss0.baidu.com', 'link.zhihu.com',
    'www.isupergeek.com', 'ss2.baidu.com', 'www.cnblogs.com', 'blog.marchtea.com',
    'secure.gravatar.com', 'ocsp.startssl.com', 'pic2.zhimg.com',
    'static.cnblogs.com', 'www.baidu.com', 'www.googletagservices.com',
    'ss3.baidu.com', 'code.jquery.com', 'gn.symcd.com', 'www.zhihu.com',
    'ssum-sec.casalemedia.com', 'zhstatic.zhihu.com', 'tpc.googlesyndication.com',
    'sp2.baidu.com', 'ocsp.digicert.com', 'sp0.baidu.com',
    'zhihu-web-analytics.zhihu.com', 'engine.adzerk.net', 'pic1.zhimg.com',
    'collector.githubapp.com', 'api.ad.cnblogs.com', 'sync.xmarks.com',
    'sp1.baidu.com', 'avatars3.githubusercontent.com', 'pic4.zhimg.com',
    'cloud.xmarks.com', 'pixel.quantserve.com', 'stats.g.doubleclick.net'];
    function FindProxyForURL(url, host) {
        if (isPlainHostName(host) // including localhost
                || shExpMatch(host, "*.local")) {
            return "DIRECT";
        }
        // only checks plain IP addresses to avoid leaking domain name
        if (/^[0-9.]+$/.test(host)) {
            if (isInNet(host, "10.0.0.0", "255.0.0.0") ||
                isInNet(host, "172.16.0.0", "255.240.0.0") ||
                isInNet(host, "192.168.0.0", "255.255.0.0") ||
                isInNet(host, "127.0.0.0", "255.255.255.0")) {
                return "DIRECT";
            }
        }
        // Lantern desktop version proxies only http(s) and ws(s)
        if (url.substring(0, 4) != 'http' && (url.substring(0, 2) != 'ws')) {
            return "DIRECT";
        }
        for (var d in bypassDomains) {
            if (host == bypassDomains[d]) {
                return "DIRECT";
            }
        }
        return "PROXY 127.0.0.1:8787; DIRECT";
}

最后一行代理地址 http://127.0.0.1:8787
获取了代理地址后就可以设置git的代理了,shell脚本如下:

    git config --global http.proxy 127.0.0.1:8787
    git config --global https.proxy 127.0.0.1:8787