仅对某些 git url/域使用代理? [英] Only use a proxy for certain git urls/domains?
问题描述
是否可以将 git 配置为仅对特定域使用代理?
Is it possible to configure git to use a proxy only for specific domains?
我想使用我们的公司代理访问 Github,但不使用它来访问我们自己的内部 git 存储库.
I'd like to use our corporate proxy to access Github but leave it off for accessing our own internal git repos.
我正在使用 bower,它需要在我们的防火墙内和 github 上都需要项目,因此我无法按照每个项目设置执行此操作.它需要是某种全局配置选项.有什么想法吗?
I'm using bower and it needs to require items both within our firewall and on github so I can't do this as a per project setting. It needs to be some kind of global configuration option. Any thoughts?
推荐答案
我通常使用环境变量:
http_proxy=http://username:password@proxydomain:port
https_proxy=http://username:password@proxydomain:port
在访问 GitHub 存储库时由 git 获取.
That is picked up by git when accessing GitHub repo.
注意:
http_proxy
和https_proxy
都必须使用代理的http://
url(没有https://
).- 始终使用
proxydomain
的 fqn(完全限定名称)(不要依赖它的简称)
- both
http_proxy
andhttps_proxy
must use thehttp://
url of the proxy (nohttps://
). - always use the fqn (full qualified name) of
proxydomain
(don't rely on its short name)
但是对于内部存储库,我所要做的就是定义并导出另一个环境变量:
But for internal repo, all I have to do is define and export one more environment variable:
no_proxy=.my.company,localhost,127.0.0.1,::1
,用于访问具有类似myrepo.my.company
或 localhost 的地址的任何存储库.
no_proxy=.my.company,localhost,127.0.0.1,::1
, for accessing any repo with an address likemyrepo.my.company
or localhost.
您可以定义NO_PROXY
或no_proxy
,没关系.
You can define NO_PROXY
or no_proxy
, it doesn't matter.
但为了以防万一,我总是设置HTTP_PROXY
、HTTPS_PROXY
、http_proxy
、https_proxy
、NO_PROXY
和 no_proxy
.
But just in case, I always set HTTP_PROXY
, HTTPS_PROXY
, http_proxy
, https_proxy
, NO_PROXY
and no_proxy
.
这篇关于仅对某些 git url/域使用代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!