Proxy servers are a pain and working round them is irritating. The instructions below should help you get your Vagrant server up and running when working behind a proxy server.
Two parts to the proxy problem
There are two parts to configuring proxy servers when using Vagrant, the first is configuring the host so that the vagrant tool can download the VM image, any plugins etc. and the second is so that the Vagrant VM can also access the internet through the proxy. It will need access if it is installing any additional pieces of software.
There are some Q & A’s out there that say use the vagrant-proxyconf, however, this solves the 2nd part of the problem and not the whole problem. You will quickly find that you cannot download the proxy plugin when you are behind a proxy! To get the plugin downloading to work you need to set the HTTP_PROXY environment variable, this will also help with tools like curl, apt-get etc. so it is a useful general tip.
So, first lets set the HTTP proxy variables on the host environment.
set HTTP_PROXY= e.g. http://user:email@example.com:8181
set HTTPS_PROXY= e.g. http://user:firstname.lastname@example.org:8181
It’s not great though because your proxy password is now available on the history of the terminal and the environment variables so, be sensible with this approach.
To install the vagrant-proxyconf plugin type the following in your terminal or command prompt.
vagrant plugin install vagrant-proxyconf
If this works then great, however, it didn’t work for me so I had to download the gem file and install it using the following:
– Download the gem file here.
– In your terminal/command prompt window change your directory to where your vagrant project is kept and run the following command:
– vagrant plugin install vagrant-proxyconf-1.4.0.gem
To verify that the plugin is installed correctly type the command.
vagrant plugin list
Once you have the plugin installed you’ll need to tweak your Vagrantfile to include the proxy details for the plugin. Place this at the bottom of your Vagrantfile after last end line.
Vagrant.configure("2") do |config| if Vagrant.has_plugin?("vagrant-proxyconf") config.proxy.http = "http://myproxyserver.local:8181" config.proxy.https = "https://myproxyserver.local:8181" config.proxy.no_proxy = "localhost,127.0.0.1" end end