git 通过代理 下载代码

236 views
Skip to first unread message

Wizard

unread,
Sep 13, 2012, 12:34:34 AM9/13/12
to shlug
用git下载代码遇到点问题,来请教一下。

我的机器在一个proxy后面,proxy是squid的,只提供了http_proxy。现在这个squid已经配置好了,
内部的机器可以用wget下载东西。 但是用git的时候有点问题。使用git协议,不是http协议。

1. squid能不能打开git的端口?
2. 如果不行的话,要怎么做。


我看了网上的这个帖子,http://www.vpsee.com/2011/07/how-to-use-git-through-a-http-proxy/
但是没有成功。

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Initialized empty Git repository in /home/user/git/linux-2.6/.git/
2012/09/13 11:41:02 socat[27248] E CONNECT git.kernel.org:9418: Forbidden
fatal: The remote end hung up unexpectedly

没有想到会是什么问题。

--
Wizard

liyaoshi

unread,
Sep 13, 2012, 12:52:42 AM9/13/12
to sh...@googlegroups.com
root@huang-vmware:/usr/src/linux-source-2.6.38# cat /bin/gitproxy
#!/bin/sh
# Use socat to proxy git through an HTTP CONNECT firewall.
# Useful if you are trying to clone git:// from inside a company.
# Requires that the proxy allows CONNECT to port 9418.
#
# Save this file as gitproxy somewhere in your path (e.g., ~/bin) and then run
#   chmod +x gitproxy
#   git config --global core.gitproxy gitproxy
#
# More details at http://tinyurl.com/8xvpny

# Configuration. Common proxy ports are 3128, 8123, 8000.
_proxy=10.10.40.10
_proxyport=80

exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport,proxyauth=username:password

root@huang-vmware:/usr/src/linux-source-2.6.38# cat /root/.config/
cat: /root/.config/: Is a directory
root@huang-vmware:/usr/src/linux-source-2.6.38# cat /root/.gitconfig
[core]
        gitproxy = gitproxy
[color]
        ui = auto
root@huang-vmware:/usr/src/linux-source-2.6.38#



--
Wizard

--
-- You received this message because you are subscribed to the Google Groups Shanghai Linux User Group group. To post to this group, send email to sh...@googlegroups.com. To unsubscribe from this group, send email to shlug+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/shlug?hl=zh-CN



Wizard

unread,
Sep 13, 2012, 1:23:55 AM9/13/12
to sh...@googlegroups.com
2012/9/13 liyaoshi <liya...@gmail.com>:
> root@huang-vmware:/usr/src/linux-source-2.6.38# cat /bin/gitproxy
> #!/bin/sh
> # Use socat to proxy git through an HTTP CONNECT firewall.
> # Useful if you are trying to clone git:// from inside a company.
> # Requires that the proxy allows CONNECT to port 9418.

9418是git repo的端口是吧。
那我在squid上要怎么允许这个端口?
--
Wizard

Wizard

unread,
Sep 13, 2012, 2:19:10 AM9/13/12
to sh...@googlegroups.com
2012/9/13 Wizard <wizard...@gmail.com>:
> 2012/9/13 liyaoshi <liya...@gmail.com>:
>> root@huang-vmware:/usr/src/linux-source-2.6.38# cat /bin/gitproxy
>> #!/bin/sh
>> # Use socat to proxy git through an HTTP CONNECT firewall.
>> # Useful if you are trying to clone git:// from inside a company.
>> # Requires that the proxy allows CONNECT to port 9418.
>
> 9418是git repo的端口是吧。
> 那我在squid上要怎么允许这个端口?
>

恩,我加了行这个好了, 但是我加到原来的Safe_ports却不行。

acl git port 9418
http_access allow git
先这么拥吧。多谢。
--
Wizard

Dannoy Lee

unread,
Sep 13, 2012, 2:27:14 AM9/13/12
to sh...@googlegroups.com
我这边加上http_proxy=http://proxy_ip:proxy_port环境变量就可以了唉
Dannoy.Lee

liyaoshi

unread,
Sep 13, 2012, 10:19:26 AM9/13/12
to sh...@googlegroups.com
你这个是http

2012/9/13 Dannoy Lee <danno...@gmail.com>

Dannoy Lee

unread,
Sep 13, 2012, 9:14:15 PM9/13/12
to sh...@googlegroups.com
能不能稍微解释一下?
我这里使用的情况是设了http_proxy之后,可以clone/push到github的,而github的那个http的url是没法push的。
还有就是ssh本来就可以通过corkscrew使用http代理的

Wizard

unread,
Sep 13, 2012, 9:59:54 PM9/13/12
to sh...@googlegroups.com
2012/9/14 Dannoy Lee <danno...@gmail.com>:
> 能不能稍微解释一下?
> 我这里使用的情况是设了http_proxy之后,可以clone/push到github的,而github的那个http的url是没法push的。
github有https的链接,你使用这么的么? 命令行贴出来看看?

Wizard

unread,
Sep 13, 2012, 11:18:29 PM9/13/12
to sh...@googlegroups.com
2012/9/13 liyaoshi <liya...@gmail.com>:
> root@huang-vmware:/usr/src/linux-source-2.6.38# cat /bin/gitproxy
> #!/bin/sh
> # Use socat to proxy git through an HTTP CONNECT firewall.
> # Useful if you are trying to clone git:// from inside a company.
> # Requires that the proxy allows CONNECT to port 9418.
> #
> # Save this file as gitproxy somewhere in your path (e.g., ~/bin) and then
> run
> # chmod +x gitproxy
> # git config --global core.gitproxy gitproxy
> #
> # More details at http://tinyurl.com/8xvpny
>
> # Configuration. Common proxy ports are 3128, 8123, 8000.
> _proxy=10.10.40.10
> _proxyport=80
>
> exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport,proxyauth=username:password

我对这个socat稍有疑问。 当core.gitproxy设置了一个命令,git clone的时候就会调用这个命令。

socat的manual上说它会去请求_proxy去打开$1:$2的连接。 但我不明白的是,为啥用STDIO?
比如说要从git.kernel.org上下载, $1就是git.kernel.org的地址,$2是9418吧。
那就是从本地机器上开一个stream,一端是stdio,另一端是proxy,然后让proxy建立到git.kernel.org:9418的连接?
我还是不明白为啥是stdio。
--
Wizard

z7z8th

unread,
Sep 15, 2012, 10:16:03 AM9/15/12
to sh...@googlegroups.com
http没用过,https的话要在.git/config里remote那个section加上自己的用户名
https://username@github.com/xxxxxx

2012/9/14 Dannoy Lee <danno...@gmail.com>
Reply all
Reply to author
Forward
0 new messages