Running Vagrant 1.8 behind a proxy

I went to the downloads page at Vagrant and downloaded the Windows Universal version. It installed without any issues.

I can open up the Windows command prompt and type

C:\Users\stephen>vagrant --version
Vagrant 1.8.1

But my issue is trying the following commands

C:\Users\stephen>vagrant init hashicorp/precise64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
C:\Users\stephen>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'hashicorp/precise64' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
The box 'hashicorp/precise64' could not be found or
could not be accessed in the remote catalog. If this is a private
box on HashiCorp's Atlas, please verify you're logged in via
`vagrant login`. Also, please double-check the name. The expanded
URL and error message are shown below:
URL: ["https://atlas.hashicorp.com/hashicorp/precise64"]
Error: SSL certificate problem: unable to get local issuer certificate
More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.

Error: SSL certificate problem: unable to get local issuer certificate

I am behind a corporate proxy. The proxy has its own certificates, so I'm guessing the problem lies there.

I am not sure why the above SSH commands failed during the vagrant up. Next I booted up PuTTY to SSH onto the machine. The address and port were listed above.

It asked for username and password. From the creating a box it appears public boxes often have vagrant as the username and vagrant as the password which worked for me.

Installing software on the new Vagrant box

Next I wanted to try installing some software, specifically NGINX, a popular web server/reverse proxy/load balancer.

Running which nginx produced no results, so it doesn't appear to be installed. Since this is an Ubuntu machine, I can use Ubuntu's package manager. First I'll run the update which is used to resynchronize the package index files from their sources, then I'll install it.

And just like that, NGINX version 1.1.19 was installed. I was sort of surprised that the virtual machine was able to reach through my corporate proxy without any issues.

I started the NGINX service by running

sudo service nginx start

I attempted to visit the webserver by opening up Chrome on my regular (non virtual box) computer and visiting 127.0.0.1 but it did not work. After some research I realized I needed to set up either port forwarding or a private network. Look for the Vagrantfile wherever you initially ran vagrant init. Mine was located at C:\Users\stephen\Vagrantfile. You can open it with any text editor. Look for the following:

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 80, host: 9090
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"

I decided to just forward the host (my Windows PC) port 9090 to the guest (the Vagrant/Ubuntu box) port 80 my uncommenting the line and changing the host port because I commonly use 8080 for other things.

NGINX listens on port 80, so this works for me. If you're running a different service, like a Rails app or Node.js/Express app, you may want to forward to whatever port those apps listen on. Alternatively you can explore the private network option above.

After modifying the Vagrantfile I ran the following in my Windows command prompt: