node.js 代理后面的凉亭

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21705091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:50:23  来源:igfitidea点击:

bower behind a proxy

node.jsproxynpmbower

提问by benek

bower installbehind a proxy fails in timeout with the following settings (some set are useless...) :

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/

I have also tried an install/uninstall of bower and a bower clean cache.

我也尝试过安装/卸载 bower 和bower clean cache.

回答by rmic

Edit your .bowerrc file and add the wanted proxy configuration:

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

{
    "proxy":"http://<host>:<port>",
    "https-proxy":"http://<host>:<port>"
}

If working behind an authenticated proxy, user and password should be included like this:

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

{
    "proxy":"http://<user>:<password>@<host>:<port>",
    "https-proxy":"http://<user>:<password>@<host>:<port>"
}

Usually, the .bowerrc is next to the bower.json. And if there is no .bowerrc file near the bower.json file, you can create one by yourself.

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

回答by edufinn

I have problem with bower listcommand, which was caused by the fact that bower use gitwith git://URLs to get the list of remote GitHub repositories, but git://protocol is blocked by our corporate firewall. In order to solve this problem in addition to setting environment variables, I have to add extra configurations to git too. Here's full list of commands I have to execute (remember to replace proxy host and port with yours):

我有问题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://

Standard environment variables in Bash are uppercased, for proxy those are HTTP_PROXYand HTTPS_PROXY, but some tools expect them to be in lowercase, bower is one of those tools. This is why I prefer to have proxy set in 2 cases: lower and upper.

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

Bower is using git to get packages from GitHub, this is why configuration keys need to be added to git too. http.proxyand https.proxyare proxy settings and should point to your proxy. Last but not least you need to tell git not to use git://protocol, because it may be blocked by firewall. You need to replace it with standard http://protocol. Someones suggest to use https://instead of git://like following: git config --global url."https://".insteadOf git://, but I was getting Connection reset by peererror, so I'm using http://, which is working fine for me.

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

At home I don't use any proxy and don't have corporate firewall, so I prefer to switch back to "normal" no-proxy settings. Here's how I do it:

在家里,我不使用任何代理,也没有公司防火墙,所以我更喜欢切换回“正常”无代理设置。这是我的方法:

# 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

I'm not very good at remembering things, so I would never remember all those commands. On top of this I'm lazy and would not want to type those long commands by hand. This is why I was creating functions to set and unset proxy settings. Here's 2 functions I've added to my .bashrcfile after some aliases definitions:

我不太擅长记住事情,所以我永远不会记住所有这些命令。最重要的是,我很懒惰,不想手动输入那些长命令。这就是我创建函数来设置和取消设置代理设置的原因。这是我.bashrc在一些别名定义后添加到我的文件中的 2 个函数:

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
}

Now when I need to set proxy, I just execute set_proxycommand, and to unset unset_proxycommand. With the help of Bash's autocomplete I don't even need to type those commands, but let tab complete them for me.

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

回答by benek

My script (using git bash on Windows) for setting proxy was executed by a different user from the one I was using for bower. The environment variables were not taken into account.

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

So the following setting is sufficient, as specified in other answers:

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

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

回答by tinyproxy

If your OS is Linux or OS X try the following command bash http_proxy='proxy server' https_proxy='proxy server' bower

如果您的操作系统是 Linux 或 OS X,请尝试以下命令 bash http_proxy='proxy server' https_proxy='proxy server' bower