ith*_*rld 88 proxy http-proxy vagrant
我公司的网络正在使用代理.因此,当我使用vagrant up它时,它向我显示了401权限错误.
如何使用vagrant做一些设置?
Ale*_*eno 97
安装proxyconf:
vagrant plugin install vagrant-proxyconf
Run Code Online (Sandbox Code Playgroud)
配置您的Vagrantfile:
config.proxy.http = "http://yourproxy:8080"
config.proxy.https = "http://yourproxy:8080"
config.proxy.no_proxy = "localhost,127.0.0.1"
Run Code Online (Sandbox Code Playgroud)
rjd*_*olb 80
如果您的代理需要身份验证,最好设置环境变量,而不是将您的密码存储在Vagrantfile中.此外,您的Vagrantfile可以被其他不在代理后面的人使用.
对于Mac/Linux(在Bash中)
export http_proxy="http://user:password@host:port"
export https_proxy="http://user:password@host:port"
vagrant plugin install vagrant-proxyconf
Run Code Online (Sandbox Code Playgroud)
然后
export VAGRANT_HTTP_PROXY=${http_proxy}
export VAGRANT_NO_PROXY="127.0.0.1"
vagrant up
Run Code Online (Sandbox Code Playgroud)
对于Windows,使用set而不是export.
set http_proxy=http://user:password@host:port
set https_proxy=https://user:password@host:port
vagrant plugin install vagrant-proxyconf
Run Code Online (Sandbox Code Playgroud)
然后
set VAGRANT_HTTP_PROXY=%http_proxy%
set VAGRANT_HTTPS_PROXY=%https_proxy%
set VAGRANT_NO_PROXY="127.0.0.1"
vagrant up
Run Code Online (Sandbox Code Playgroud)
小智 53
安装proxyconf会解决这个问题,但是在代理后面你无法使用命令安装插件vagrant plugin install,Bundler会引发错误.
如果您正在使用类似unix的系统,请在您的环境中设置代理
export http_proxy=http://user:password@host:port
Run Code Online (Sandbox Code Playgroud)
或者在这里获得更详细的答案:如何在代理服务器后面使用捆绑包?
在此之后设置proxyconf
qua*_*ous 27
自动检测您的代理设置并将其注入所有流浪的VM中
安装代理插件
vagrant plugin install vagrant-proxyconf
Run Code Online (Sandbox Code Playgroud)
将此conf添加到您的私人/用户VagrantFile(它将为您的所有项目执行):
vi $HOME/.vagrant.d/Vagrantfile
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
现在你的VM!
sna*_*cks 11
在Windows主机上
打开CMD提示;
set HTTP_PROXY=http://proxy.yourcorp.com:80
set HTTPS_PROXY=https://proxy.yourcorp.com:443
Run Code Online (Sandbox Code Playgroud)
将上述代码段中的地址和端口替换为适合您情况的内容.在您关闭CMD提示之前,上述内容将保持设置状态.如果它适合您,请考虑将它们永久地添加到您的环境变量中,这样您就不必在每次打开新的CMD提示时都设置它们.
在Windows上,您必须设置一个变量来指定代理设置,下载vagrant-proxyconf插件:(用正确的值替换{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}
Run Code Online (Sandbox Code Playgroud)
之后,您可以添加插件以在vagrant文件中对代理设置进行硬编码
vagrant plugin install vagrant-proxyconf --plugin-source http://rubygems.org
Run Code Online (Sandbox Code Playgroud)
然后,您可以在Vagrantfile中提供config.proxy.xxx设置,使其独立于环境设置变量
You will want to install the plugin proxyconf since this makes configuring the proxy for the guest machines pretty straight forward in the VagrantFile
config.proxy.http = "http://proxy:8888"
config.proxy.https = "http://proxy:8883"
config.proxy.no_proxy = "localhost,127.0.0.1"
Run Code Online (Sandbox Code Playgroud)
However, there's quite a few things that could still go wrong. Firstly, you probably can't install vagrant plugins when behind the proxy. If that's the case you should download the source e.g. from rubygems.org and install from source
$ vagrant plugin install vagrant-proxyconf --plugin-source file://fully/qualified/path/vagrant-proxyconf-1.x.0.gem
Run Code Online (Sandbox Code Playgroud)
If you solve that problem you might have the fortune of being behind an NTLM proxy, which means that if you are using *nix on your guest machines then you still have some way to go, because NTLM authentication is not supported natively There are many ways of solving that. I've used CNTLM to solve tht part of the puzzle. It acts as glue between standard authorization protocols and NTLM
For a complete walk through, have a look at this blog entry about setting vagrant up behind a corporate proxy