【问题标题】:bower behind a proxy代理后面的凉亭
【发布时间】:2014-03-09 10:19:32
【问题描述】:

代理后面的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/

我还尝试了安装/卸载 bower 和 bower clean cache

【问题讨论】:

  • bower proxy configuration 的可能重复项
  • 很好地汇编了我们必须做的一切以使一切正常!做得好! :+1:

标签: node.js proxy npm bower


【解决方案1】:

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

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

如果在经过身份验证的代理后面工作,用户和密码应该像这样包含:

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

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

【讨论】:

  • 在你的用户目录下创建.bowerrc文件~/.bowerrc
  • 您也可以在 Windows 上的 C:\Users\{Username}\.bowerrc 中执行此操作
  • @rmic 如何在 windows 中找到
  • @Kartheeks 不确定是否理解您的问题。 是代理。
  • 注意在 https-proxy 中使用 http://。它对我有用——正如提到的HERE
【解决方案2】:

bower list 命令有问题,这是由于 bower 使用 gitgit:// URL 来获取远程 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://

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

Bower 使用 git 从 GitHub 获取包,这就是为什么配置键也需要添加到 git 的原因。 http.proxyhttps.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

我不太擅长记住事情,所以我永远不会记住所有这些命令。除此之外,我很懒,不想手动输入那些长命令。这就是为什么我要创建函数来设置和取消设置代理设置。这是我在一些别名定义之后添加到我的.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
}

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

【讨论】:

  • 这为我解决了问题。 bower searchbower install 工作正常,但 bower list 不行。不过需要注意的一点是,如果您的网络有多个代理服务器,请确保您在此处使用与 ~/.bowerrc 中相同的代理,否则您将收到 503 和/或连接超时!
【解决方案3】:

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

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

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

【讨论】:

    【解决方案4】:

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

    【讨论】:

      猜你喜欢
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-14
      • 2016-06-08
      • 2016-02-03
      相关资源
      最近更新 更多