Proxy 如何在代理环境中使用vagrant?

Proxy 如何在代理环境中使用vagrant?,proxy,vagrant,http-proxy,Proxy,Vagrant,Http Proxy,我公司的网络正在使用代理。因此,当我使用vagrant up时,它显示了一个401权限错误 如何设置使用vagrant?安装proxyconf: vagrant plugin install vagrant-proxyconf 配置您的文件: config.proxy.http = "http://yourproxy:8080" config.proxy.https = "http://yourproxy:8080" config.proxy.no_proxy = "localh

我公司的网络正在使用代理。因此,当我使用
vagrant up
时,它显示了一个401权限错误

如何设置使用vagrant?

安装proxyconf:

vagrant plugin install vagrant-proxyconf
配置您的文件:

config.proxy.http     = "http://yourproxy:8080"
config.proxy.https    = "http://yourproxy:8080"
config.proxy.no_proxy = "localhost,127.0.0.1"

安装proxyconf可以解决这个问题,但是在代理之后,您不能简单地使用命令
vagrant plugin install
安装插件,Bundler将引发一个错误

如果使用的是类unix系统,请在环境中设置代理

export http_proxy=http://user:password@host:port
或者在这里获得更详细的答案:


设置proxyconf之后,如果代理需要身份验证,最好设置环境变量,而不是将密码存储在文件中。 此外,您的Vagrantfile还可以被不支持代理的其他人轻松使用

适用于Mac/Linux(在Bash中)

然后

对于Windows,使用集合而不是导出。

set http_proxy=http://user:password@host:port
set https_proxy=https://user:password@host:port
vagrant plugin install vagrant-proxyconf
然后


自动检测您的代理设置,并将它们注入到您所有的vagrant VM中

安装代理插件

vagrant plugin install vagrant-proxyconf
将此配置添加到您的私有/用户文件(将对您的所有项目执行):




现在打开你的虚拟机

在MS Windows中,这适用于我们:

set http_proxy=< proxy_url >
set https_proxy=< proxy_url >
set http\u proxy=
设置https\u proxy=
以及*nix的等效值:

export http_proxy=< proxy_url >
export https_proxy=< proxy_url >
export http\u proxy=
导出https\u proxy=
在Windows主机上

打开CMD提示符

set HTTP_PROXY=http://proxy.yourcorp.com:80
set HTTPS_PROXY=https://proxy.yourcorp.com:443

将上述代码段中的地址和端口替换为适合您的情况的地址和端口。在关闭CMD提示符之前,上述设置将保持不变。如果它对你有用,考虑将它们永久地添加到环境变量中,这样你就不必每次打开新的CMD提示符时设置它们。

< P>问题不提及VM提供程序,但在我的例子中,我在同一环境下使用虚拟框。虚拟盒GUI中有一个选项,我需要启用该选项才能使其正常工作。位于虚拟盒应用程序首选项中:文件>>首选项…>>代理。一旦我配置了这个,我就可以毫无问题地工作了。希望这个提示也能帮助你们

在windows上,您必须设置一个变量来指定代理设置,下载vagrant proxyconf插件:(用正确的值替换{proxy_SCHEME}(http://或https://)、{proxy_IP}和{proxy_PORT})

之后,您可以将插件添加到vagrant文件中的代理设置硬编码中

vagrant plugin install vagrant-proxyconf --plugin-source http://rubygems.org

然后,您可以在Vagrant文件中提供config.proxy.xxx设置,使其独立于环境设置变量

您需要安装插件proxyconf,因为这使得在Vagrant文件中为来宾计算机配置代理非常简单

config.proxy.http     = "http://proxy:8888"
config.proxy.https    = "http://proxy:8883"
config.proxy.no_proxy = "localhost,127.0.0.1"
然而,仍然有很多事情可能会出错。 首先,您可能无法在代理之后安装vagrant插件。如果是这种情况,您应该下载源代码,例如从rubygems.org下载并从源代码安装

$ vagrant plugin install vagrant-proxyconf --plugin-source file://fully/qualified/path/vagrant-proxyconf-1.x.0.gem
如果您解决了这个问题,您可能有幸使用NTLM代理,这意味着如果您在来宾计算机上使用*nix,那么您还有一些路要走,因为NTLM身份验证在本机上不受支持 有很多方法可以解决这个问题。我用CNTLM解决了这部分难题。它充当标准授权协议和NTLM之间的粘合剂


如果您确实希望代理配置和插件安装在您的vagrant文件中,例如,如果您只是为您的公司环境制作一个vagrant文件,并且不能让用户编辑环境变量,那么请查看关于在公司代理后设置vagrant的完整演练,这就是我的答案:

ENV['http_proxy']  = 'http://proxyhost:proxyport'
ENV['https_proxy'] = 'http://proxyhost:proxyport'

# Plugin installation procedure from http://stackoverflow.com/a/28801317
required_plugins = %w(vagrant-proxyconf)

plugins_to_install = required_plugins.select { |plugin| not Vagrant.has_plugin? plugin }
if not plugins_to_install.empty?
  puts "Installing plugins: #{plugins_to_install.join(' ')}"
  if system "vagrant plugin install #{plugins_to_install.join(' ')}"
    exec "vagrant #{ARGV.join(' ')}"
  else
    abort "Installation of one or more plugins has failed. Aborting."
  end
end

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.proxy.http     = "#{ENV['http_proxy']}"
  config.proxy.https    = "#{ENV['https_proxy']}"
  config.proxy.no_proxy = "localhost,127.0.0.1"
  # and so on

(如果没有,只需将它们设置为环境变量,就像其他答案所说的那样,并从config.proxy.http(s)指令中的env中引用它们即可。)

密码中的某些特殊字符会在代理中产生问题。要么转义它们,要么避免在密码中使用特殊字符。

在PowerShell中,您可以设置http\u代理和https\u代理环境变量,如下所示:

$env:http_proxy="http://proxy:3128"
$env:https_proxy="http://proxy:3128"

你在谷歌上搜索过这个吗?对不起,我没有。现在我知道了
vagrant plugin install vagrant proxyconf
。但是在我安装并将我的代理url设置为config文件后,结果是一样的。401
config.env_proxy.
从版本2.0开始就被弃用,并被
config.proxy.
替换为
config.proxy.https="https://yourproxy:8080“
是第二行的
https
还是
http
,两者都可以。在我的公司中,http和https通过的代理与我运行“vagrant plugin install vagrant proxyconf”时httpOk中的代理相同。它击中了我的代理?需要指出的是,如果你在代理后面,你就不能安装插件。在windows上,我按照你的建议做了,但使用了“SET”而不是“export”。按预期工作,无需对vagrant文件进行任何更改。只需一个附加参数(rubygem从https到http),以避免验证SSL证书时出错:
vagrant plugin安装vagrant proxyconf——插件源代码http://rubygems.org
这是比以前的解决方案更好的解决方案,因为这个不需要其他任何东西。其他解决方案(安装插件)需要先设置免费internet访问才能这样做。此外,如果您不想让它留在您的环境中,您可以执行VAGRANT_HTTP_PROXY=“”VAGRANT up(无需导出或设置)这是一个很好的解决方案,因为它不需要将代理设置放在vagrant文件中,而这些设置显然不属于Windows PowerShell v6.0:$env:http_proxy=”“$env:https_proxy=”“vagrant插件安装vagrant proxyconf对于使用Windows Git Bash的用户,请使用Mac/Linux(在Bash中)说明。例如:export http_proxy=”“您忘记(?)到
export VAGRANT_HTTPS_proxy=${HTTPS_proxy}set http_proxy={PROXY_SCHEME}{PROXY_IP}:{PROXY_PORT}
set https_proxy={PROXY_SCHEME}{PROXY_IP}:{PROXY_PORT}
vagrant plugin install vagrant-proxyconf --plugin-source http://rubygems.org
config.proxy.http     = "http://proxy:8888"
config.proxy.https    = "http://proxy:8883"
config.proxy.no_proxy = "localhost,127.0.0.1"
$ vagrant plugin install vagrant-proxyconf --plugin-source file://fully/qualified/path/vagrant-proxyconf-1.x.0.gem
ENV['http_proxy']  = 'http://proxyhost:proxyport'
ENV['https_proxy'] = 'http://proxyhost:proxyport'

# Plugin installation procedure from http://stackoverflow.com/a/28801317
required_plugins = %w(vagrant-proxyconf)

plugins_to_install = required_plugins.select { |plugin| not Vagrant.has_plugin? plugin }
if not plugins_to_install.empty?
  puts "Installing plugins: #{plugins_to_install.join(' ')}"
  if system "vagrant plugin install #{plugins_to_install.join(' ')}"
    exec "vagrant #{ARGV.join(' ')}"
  else
    abort "Installation of one or more plugins has failed. Aborting."
  end
end

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.proxy.http     = "#{ENV['http_proxy']}"
  config.proxy.https    = "#{ENV['https_proxy']}"
  config.proxy.no_proxy = "localhost,127.0.0.1"
  # and so on
$env:http_proxy="http://proxy:3128"
$env:https_proxy="http://proxy:3128"