代理人背后的凉亭

ben*_*nek 49 proxy node.js npm bower

bower install 在代理后面使用以下设置在超时时失败(某些设置无用......):

git config --global http.proxy fr-proxy.example.com:3128
git config --global https.proxy fr-proxy.example.com:3128

export http_proxy=http://fr-proxy.example.com:3128
export https_proxy=http://fr-proxy.example.com:3128

npm config set proxy http://fr-proxy.example.com:3128
npm config set https-proxy http://fr-proxy.example.com:3128

npm config set registry http://registry.npmjs.org/
Run Code Online (Sandbox Code Playgroud)

我也试过安装/卸载凉亭和一个bower clean cache.

小智 98

编辑.bowerrc文件并添加所需的代理配置:

{
    "proxy":"http://<host>:<port>",
    "https-proxy":"http://<host>:<port>"
}
Run Code Online (Sandbox Code Playgroud)

如果在经过身份验证的代理后面工作,则应包含用户和密码,如下所示:

{
    "proxy":"http://<user>:<password>@<host>:<port>",
    "https-proxy":"http://<user>:<password>@<host>:<port>"
}
Run Code Online (Sandbox Code Playgroud)

通常,.bowerrc位于bower.json旁边.如果bower.json文件附近没有.bowerrc文件,您可以自己创建一个.bowerrc文件.

  • 只需在用户目录中创建.bowerrc文件*〜/ .bowerrc* (13认同)
  • 您也可以在Windows上的C:\ Users\{Username} \.bowerrc中执行此操作 (9认同)
  • 注意在https-proxy中使用http://.它为我做了诀窍 - 如上所述[HERE](http://stackoverflow.com/a/23288312/4420532) (2认同)

edu*_*inn 30

我有问题bower list的命令,这是由事实凉亭使用造成gitgit://网址,获取远程的GitHub库的名单,但git://协议是由我们公司的防火墙阻止.除了设置环境变量之外,为了解决这个问题,我还需要为git添加额外的配置.这是我必须执行的命令的完整列表(记得用你的命令替换代理主机和端口):

# set proxy for command line tools
export HTTP_PROXY=http://localhost:3128
export HTTPS_PROXY=http://localhost:3128
export http_proxy=http://localhost:3128
export https_proxy=http://localhost:3128

# add configuration to git command line tool
git config --global http.proxy http://localhost:3128
git config --global https.proxy http://localhost:3128
git config --global url."http://".insteadOf git://
Run Code Online (Sandbox Code Playgroud)

Bash中的标准环境变量是大写的,对于代理那些是HTTP_PROXYHTTPS_PROXY,但是有些工具希望它们是小写的,bower就是这些工具之一.这就是为什么我更喜欢在2种情况下设置代理:低级和高级.

Bower使用git从GitHub获取包,这就是为什么配置键也需要添加到git的原因.http.proxy并且https.proxy是代理设置,应该指向您的代理.最后但并非最不重要的是,您需要告诉git不要使用git://协议,因为它可能被防火墙阻止.您需要使用标准http://协议替换它.有人建议使用https://而不是git://像下面这样:git config --global url."https://".insteadOf git://但是我得到了Connection reset by peer错误,所以我正在使用http://,这对我来说很好.

在家里我不使用任何代理,也没有企业防火墙,所以我更愿意切换回"正常"无代理设置.我是这样做的:

# remove proxy environment variables
unset HTTP_PROXY
unset HTTPS_PROXY
unset http_proxy
unset https_proxy
# remove git configurations

git config --global --unset http.proxy
git config --global --unset https.proxy
git config --global --unset url."http://".insteadOf
Run Code Online (Sandbox Code Playgroud)

我不太善于记住事情,所以我永远不会记得那些命令.除此之外,我很懒,不想手工输入那些长命令.这就是我创建设置和取消设置代理设置的功能的原因.这是我.bashrc在一些别名定义后添加到我的文件中的两个函数:

set_proxy() {
    export HTTP_PROXY=http://localhost:3128
    export HTTPS_PROXY=http://localhost:3128
    # some tools uses lowercase env variables
    export http_proxy=http://localhost:3128
    export https_proxy=http://localhost:3128
    # config git
    git config --global http.proxy http://localhost:3128
    git config --global https.proxy http://localhost:3128
    git config --global url."http://".insteadOf git://
}
unset_proxy() {
    unset HTTP_PROXY
    unset HTTPS_PROXY
    unset http_proxy
    unset https_proxy
    git config --global --unset http.proxy
    git config --global --unset https.proxy
    git config --global --unset url."http://".insteadOf
}
Run Code Online (Sandbox Code Playgroud)

现在,当我需要设置代理时,我只执行set_proxy命令,并取消设置unset_proxy命令.在Bash自动完成的帮助下,我甚至不需要输入这些命令,但让tab为我完成它们.


ben*_*nek 6

我的脚本(在Windows上使用git bash)用于设置代理由与我用于bower的用户不同的用户执行.没有考虑环境变量.

因此,以下设置就足够了,如其他答案所述:

export http_proxy=http://fr-proxy.example.com:3128
export https_proxy=http://fr-proxy.example.com:3128
Run Code Online (Sandbox Code Playgroud)