如何在代理环境中使用stream浪汉?

我公司的networking正在使用代理。 所以当我使用vagrant up ,它给了我一个401权限的错误。

我怎样才能做一些设置来使用stream浪汉?

安装proxyconf:

 vagrant plugin install vagrant-proxyconf 

configuration您的Vagrantfile:

 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 

或者在这里得到更详细的答案: 如何在代理后面使用bundler?

此后设置proxyconf

如果您的代理需要身份validation,最好设置环境variables而不是将您的密码存储在Vagrantfile中。 另外你的Vagrantfile可以被别人轻松地使用,不在代理之后。

对于Mac / Linux(在Bash中)

 export http_proxy="http://user:password@host:port" vagrant plugin install vagrant-proxyconf 

然后

 export VAGRANT_HTTP_PROXY="http://user:password@host:port" export VAGRANT_NO_PROXY="127.0.0.1" vagrant up 

对于Windows使用设置,而不是导出。

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

然后

 set VAGRANT_HTTP_PROXY="http://user:password@host:port" set VAGRANT_NO_PROXY="127.0.0.1" vagrant up 

自动检测您的代理设置,并将其注入到您的所有stream浪虚拟机中

安装代理插件

 vagrant plugin install vagrant-proxyconf 

将这个conf添加到你的私人/用户VagrantFile(它会被执行所有你的项目):

 vi $HOME/.vagrant.d/Vagrantfile 

 Vagrant.configure("2") do |config| puts "proxyconf..." if Vagrant.has_plugin?("vagrant-proxyconf") puts "find proxyconf plugin !" if ENV["http_proxy"] puts "http_proxy: " + ENV["http_proxy"] config.proxy.http = ENV["http_proxy"] end if ENV["https_proxy"] puts "https_proxy: " + ENV["https_proxy"] config.proxy.https = ENV["https_proxy"] end if ENV["no_proxy"] config.proxy.no_proxy = ENV["no_proxy"] end end end 

现在你的虚拟机!

在Windows主机上

打开一个CMD提示符;

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

用上面的代码片段中的地址和端口代替任何适合你的情况。 上述内容将保持设置,直到closuresCMD提示符。 如果它适用于您,请考虑将它们永久添加到您的环境variables中,以便您不必在每次打开新的CMD提示时都设置它们。

在windows上 ,你必须设置一个variables来指定代理设置,下载vagrant-proxyconf插件:(用正确的值replace{PROXY_SCHEME}(http://或https://),{PROXY_IP}和{PROXY_PORT})

 set http_proxy={PROXY_SCHEME}{PROXY_IP}:{PROXY_PORT} set https_proxy={PROXY_SCHEME}{PROXY_IP}:{PROXY_PORT} 

之后,你可以添加插件来硬编码在vagrant文​​件中的代理设置

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

然后您可以在您的Vagrantfile中提供config.proxy.xxx设置,以独立于环境设置variables

您将需要安装插件proxyconf,因为这使得在VagrantFile中非常简单地configuration来宾机器的代理

 config.proxy.http = "http://proxy:8888" config.proxy.https = "http://proxy:8883" config.proxy.no_proxy = "localhost,127.0.0.1" 

但是,还是有很多事情可能会出错。 首先,你可能无法安装在代理后面的stream浪插件。 如果是这种情况,你应该从rubygems.org下载源代码,并从源代码安装

 $ vagrant plugin install vagrant-proxyconf --plugin-source file://fully/qualified/path/vagrant-proxyconf-1.x.0.gem 

如果你解决了这个问题,你可能有一个NTLM代理的后面,这意味着如果你在你的客户机上使用* nix,那么你还有一段路要走,因为NTLM身份validation不是本地支持的。解决这个问题。 我已经使用CNTLM来解决这个难题的一部分。 它充当标准授权协议和NTLM之间的粘合剂

想了解一个完整的步骤,看看这个博客文章,关于在公司代理背后设置stream浪汉

这个问题没有提到VM提供者,但在我的情况下,我在相同的环境下使用Virtual Box。 Virtual Box GUI中有一个选项,我需要启用才能使其工作。 位于Virtual Box应用程序首选项: 文件>>首选项… >>代理 。 一旦我configuration了这个,我就可以毫无问题地工作。 希望这个提示也可以帮助你们。

如果你真的想要你的代理configuration和插件安装在你的Vagrant文​​件中,例如,如果你只是为你的企业环境制作一个Vagrantfile,并且不能让用户编辑环境variables,那么这就是我的答案:

 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 

(如果你不这样做,只要将它们设置为像其他答案一样的环境variables,并从config.proxy.http(s)指令的env中引用它们。)

在MS Windows中,这对我们有效:

 set http_proxy=< proxy_url > set https_proxy=< proxy_url > 

和* nix的等价物:

 export http_proxy=< proxy_url > export https_proxy=< proxy_url > 

在密码中的一些特殊字符在代理中创build问题。 要么逃避它们,要么避免在密码中包含特殊字符。