NutzCN Logo
分享 Github使用代理的办法
发布于 2660天前 作者 wendal 1724 次浏览 复制 上一个帖子 下一个帖子
标签:

假设你有ss的1080的sockt5代理

git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'

还有一个问题,就是使用socialauth进行github登录的时候, 服务器怎么办呢?

socialauth的HttpUtil提供了设置代理的方法,但是,兼顾github和qq登陆的情况下, 全部走代理不是最优解.

所以,强行修改其源码

			URL url = new URL(urlStr);
			if (urlStr.startsWith("https://github")) {
			    try {
			        Socket socket = new Socket();
			        socket.connect(ssLocal, 1000);
			        socket.close();
                                log.debug("using ss-local");
			        conn = (HttpURLConnection) url.openConnection(new Proxy(Type.SOCKS, ssLocal));
			    } catch (Exception e) {
                               log.debug("ss-local not running?");
                           }
			}
			if (conn == null) {
			    if (proxyObj != null) {
			        conn = (HttpURLConnection) url.openConnection(proxyObj);
			    } else {
			        conn = (HttpURLConnection) url.openConnection();
			    }
			}
2 回复

漏写了一句

public static InetSocketAddress ssLocal = new InetSocketAddress("127.0.0.1", 1080);

补充一下走ssh协议的代理设置, 就是配置.ssh/config文件.

root@master:~# cat .ssh/config
Host github.com
  ProxyCommand=nc -X 5 -x 127.0.0.1:1080 %h %p
添加回复
请先登陆
回到顶部