A Vagrant plugin that configures the virtual machine to use specified proxies. This is useful for example in case you are behind a corporate proxy server, or you have a caching proxy (for example polipo).
At this state we support:
- Generic
http_proxy
etc. environment variables that many programs support - APT proxy/cacher
- Setting default proxy configuration for all Chef provisioners
Install the plugin:
vagrant plugin install vagrant-proxyconf
To configure all possible software on all Vagrant VMs, add the following to $HOME/.vagrant.d/Vagrantfile (or to a project specific Vagrantfile):
Vagrant.configure("2") do |config|
config.proxy.http = "http://192.168.0.2:3128/"
config.proxy.https = "http://192.168.0.2:3128/"
config.proxy.no_proxy = "localhost,127.0.0.1,.example.com"
# ... other stuff
end
This plugin requires Vagrant 1.2 or newer (downloads).
The plugin is supposed to be compatible with all Vagrant providers and other plugins. Please file an issue if this is not the case. The following providers are confirmed to work: AWS, Digital Ocean, VirtualBox, VMware Fusion.
For the proxy configuration to take effect for vagrant-omnibus plugin, version 1.1.1 or newer of it should be used.
Install using standard Vagrant plugin installation method: vagrant plugin install vagrant-proxyconf
. See the wiki for instructions to install a pre-release version.
The plugin hooks itself to all Vagrant commands triggering provisioning (e.g. vagrant up
, vagrant provision
, etc.). The proxy configurations are written just before provisioners are run.
Proxy settings can be configured in Vagrantfile. In the common case that you want to use the same configuration in all Vagrant machines, you can use $HOME/.vagrant.d/Vagrantfile or environment variables. Platform specific settings are only used on virtual machines that support them (i.e. Apt configuration on Debian based systems), so there is no harm using global configuration.
Project specific Vagrantfile overrides global settings. Environment variables override both.
It's a common case that you want all possible connections to pass through the same proxy. This will set the default values for all other proxy configuration keys. It also sets default proxy configuration for all Chef Solo and Chef Client provisioners.
Vagrant.configure("2") do |config|
config.proxy.http = "http://192.168.0.2:3128/"
config.proxy.https = "http://192.168.0.2:3128/"
config.proxy.no_proxy = "localhost,127.0.0.1,.example.com"
# ... other stuff
end
config.proxy.http
- The proxy for HTTP URIsconfig.proxy.https
- The proxy for HTTPS URIsconfig.proxy.ftp
- The proxy for FTP URIsconfig.proxy.no_proxy
- A comma separated list of hosts or domains which do not use proxies.
- If all keys are unset or
nil
, no configuration is written. - A proxy should be specified in the form of protocol://[user:pass@]host[:port].
- Empty string (
""
) orfalse
in any setting also force the configuration files to be written, but without configuration for that key. Can be used to clear the old configuration and/or override a global setting.
VAGRANT_HTTP_PROXY
VAGRANT_HTTPS_PROXY
VAGRANT_FTP_PROXY
VAGRANT_NO_PROXY
These also override the Vagrantfile configuration. To disable or remove the proxy use an empty value.
For example to spin up a VM, run:
VAGRANT_HTTP_PROXY="http://proxy.example.com:8080" vagrant up
Many programs (wget, curl, yum, etc.) can be configured to use proxies with <protocol>_proxy
or <PROTOCOL>_PROXY
environment variables. This configuration will be written to /etc/profile.d/proxy.sh on the guest.
Also sudo will be configured to preserve the variables. This requires that sudo in the VM is configured to support "sudoers.d", i.e. /etc/sudoers contains line #includedir /etc/sudoers.d
.
Vagrant.configure("2") do |config|
config.env_proxy.http = "http://192.168.33.200:8888/"
config.env_proxy.https = "$http_proxy"
config.env_proxy.no_proxy = "localhost,127.0.0.1,.example.com"
# ... other stuff
end
config.env_proxy.http
- The proxy for HTTP URIsconfig.env_proxy.https
- The proxy for HTTPS URIsconfig.env_proxy.ftp
- The proxy for FTP URIsconfig.env_proxy.no_proxy
- A comma separated list of hosts or domains which do not use proxies.
- If all keys are unset or
nil
, no configuration is written. - A proxy can be specified in the form of protocol://[user:pass@]host[:port].
- The values are used as specified, so you can use for example variables that will be evaluated by the shell on the VM.
- Empty string (
""
) orfalse
in any setting also force the configuration file to be written, but without configuration for that key. Can be used to clear the old configuration and/or override a global setting.
VAGRANT_ENV_HTTP_PROXY
VAGRANT_ENV_HTTPS_PROXY
VAGRANT_ENV_FTP_PROXY
VAGRANT_ENV_NO_PROXY
These also override the Vagrantfile configuration. To disable or remove the proxy use an empty value.
For example to spin up a VM, run:
VAGRANT_ENV_HTTP_PROXY="http://proxy.example.com:8080" vagrant up
Configures Apt to use the specified proxy settings. The configuration will be written to /etc/apt/apt.conf.d/01proxy on the guest.
Vagrant.configure("2") do |config|
config.apt_proxy.http = "192.168.33.1:3142"
config.apt_proxy.https = "DIRECT"
# ... other stuff
end
config.apt_proxy.http
- The proxy for HTTP URIsconfig.apt_proxy.https
- The proxy for HTTPS URIsconfig.apt_proxy.ftp
- The proxy for FTP URIs
- If all keys are unset or
nil
, no configuration is written. - A proxy can be specified in the form of [http://][user:pass@]host[:port]. So all but the host part are optional. The default port is 3142 and protocol is the same as the key.
- Empty string (
""
) orfalse
in any protocol also force the configuration file to be written, but without configuration for that protocol. Can be used to clear the old configuration and/or override a global setting. "DIRECT"
can be used to specify that no proxy should be used. This is mostly useful for disabling proxy for HTTPS URIs when HTTP proxy is set (as Apt defaults to the latter).- Please refer to apt.conf(5) manual for more information.
VAGRANT_APT_HTTP_PROXY
VAGRANT_APT_HTTPS_PROXY
VAGRANT_APT_FTP_PROXY
These also override the Vagrantfile configuration. To disable or remove the proxy use "DIRECT" or an empty value.
For example to spin up a VM, run:
VAGRANT_APT_HTTP_PROXY="proxy.example.com:8080" vagrant up
apt-cacher-box gives an example for setting up apt-cacher proxy server in a Vagrant VM.
- apt-cacher-box
a Vagrant setup for apt-cacher-ng. - polipo-box
a Vagrant setup for polipo caching web proxy. - vagrant-cachier
An excellent Vagrant plugin that shares various cache directories among similar VM instances. Should work fine together with vagrant-proxyconf.