如何配置 Vagrant 来设置代理并使用它?

mli*_*elt 4 proxy vagrant

我有以下设置:

  • 视窗 7 电脑
  • 安装 Ruby、Vagrant、VirtualBox
  • VBox 图像 Ubuntu 14.x
  • 在我公司的内网工作,需要代理上网

通过将环境变量设置http_proxy为我们的代理,我能够为用户 vagrant 配置 VBox 图像以访问互联网。但是,当我尝试在 shell 配置器中设置代理时,我遇到了问题。以下是定义代理的脚本部分,以及首次访问互联网的部分:

# Base setup proxy and DISPLAY
set HTTP_PROXY=http://proxy.name.com:8080
echo "Add proxy to necessary parts"
echo 'export http_proxy=http://proxy.name.com:8080' >> ~vagrant/.bash_profile
echo 'export DISPLAY=192.168.137.1:0.0' >> ~vagrant/.bash_profile
echo 'export http_proxy=http://proxy.name.com:8080' >> /root/.bash_profile
export http_proxy=$HTTP_PROXY

# Install Git
echo "Install Git"
apt-get update
apt-get install -y git
...
Run Code Online (Sandbox Code Playgroud)

但是,我得到以下输出:

Add proxy to necessary parts
Install Git
Err http://security.ubuntu.com trusty-security InRelease

Err http://archive.ubuntu.com trusty InRelease

Err http://archive.ubuntu.com trusty-updates InRelease

Err http://security.ubuntu.com trusty-security Release.gpg
  Could not resolve 'security.ubuntu.com'
Err http://archive.ubuntu.com trusty Release.gpg
  Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com trusty-updates Release.gpg
  Could not resolve 'archive.ubuntu.com'
Reading package lists...
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/InRelease
...
Run Code Online (Sandbox Code Playgroud)

如何在 Unix 脚本中设置代理并立即使用它,以便可以使用apt-get, git clone, ... ?

小智 9

有一个插件!

安装vagrant-proxyconf

vagrant plugin install vagrant-proxyconf
Run Code Online (Sandbox Code Playgroud)

配置它(在所有 Vagrant VM 的$HOME/.vagrant.d/Vagrantfile中):

Vagrant.configure("2") do |config|
  if Vagrant.has_plugin?("vagrant-proxyconf")
    config.proxy.http     = "http://10.206.246.20:8080"
    config.proxy.https    = "http://10.206.246.20:8080"
    config.proxy.no_proxy = "localhost,127.0.0.1"
  end
end
Run Code Online (Sandbox Code Playgroud)