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.

Here's what worked

C:\Users\stephen>set HTTP_PROXY=http://myproxyhost:8080
C:\Users\stephen>set HTTPS_PROXY=http://myproxyhost:8080
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
==> default: Loading metadata for box 'hashicorp/precise64'
    default: URL: https://atlas.hashicorp.com/hashicorp/precise64
==> default: Adding box 'hashicorp/precise64' (v1.1.0) for provider: virtualbox
    default: Downloading: https://atlas.hashicorp.com/hashicorp/boxes/precise64/versions/1.1.0/providers/virtualbox.box
    default: Progress: 6% (Rate: 388k/s, Estimated time remaining: 0:12:29)

It then took about 15 minutes to download and install the box. Here's the remaining output

==> default: Successfully added box 'hashicorp/precise64' (v1.1.0) for 'virtualbox'!
==> default: Importing base box 'hashicorp/precise64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise64' is up to date...
==> default: Setting the name of the VM: stephen_default_1455046555847_29926
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 4.2.0
    default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
    default: /vagrant => C:/Users/stephen
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

chown `id -u vagrant`:`id -g vagrant` /vagrant

Stdout from the command:



Stderr from the command:

stdin: is not a tty
chown: changing ownership of `/vagrant': Not a directory

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.

vagrant@precise64:~$ which nginx
vagrant@precise64:~$ sudo apt-get update
Ign http://us.archive.ubuntu.com precise InRelease
Get:1 http://us.archive.ubuntu.com precise-updates InRelease [196 kB]
Get:2 http://security.ubuntu.com precise-security InRelease [54.5 kB]
Get:3 http://us.archive.ubuntu.com precise-backports InRelease [54.5 kB]
Hit http://us.archive.ubuntu.com precise Release.gpg
Get:4 http://us.archive.ubuntu.com precise-updates/main Sources [495 kB]
...
Fetched 6,448 kB in 24s (266 kB/s)
Reading package lists... Done
vagrant@precise64:~$ sudo apt-get install nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libgd2-noxpm libjpeg-turbo8 libjpeg8 libxslt1.1 nginx-common nginx-full
Suggested packages:
  libgd-tools
The following NEW packages will be installed:
  libgd2-noxpm libjpeg-turbo8 libjpeg8 libxslt1.1 nginx nginx-common nginx-full
0 upgraded, 7 newly installed, 0 to remove and 185 not upgraded.
Need to get 882 kB of archives.
After this operation, 2,694 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
...
...
Selecting previously unselected package nginx.
Unpacking nginx (from .../nginx_1.1.19-1ubuntu0.8_all.deb) ...
Processing triggers for man-db ...
Processing triggers for ureadahead ...
ureadahead will be reprofiled on next reboot
Processing triggers for ufw ...
Setting up libjpeg-turbo8 (1.1.90+svn733-0ubuntu4.4) ...
Setting up libxslt1.1 (1.1.26-8ubuntu1.3) ...
Setting up libjpeg8 (8c-2ubuntu7) ...
Setting up libgd2-noxpm (2.0.36~rc1~dfsg-6ubuntu2) ...
Setting up nginx-common (1.1.19-1ubuntu0.8) ...
Setting up nginx-full (1.1.19-1ubuntu0.8) ...
Setting up nginx (1.1.19-1ubuntu0.8) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
vagrant@precise64:~$ nginx -v
nginx version: nginx/1.1.19

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:

C:\Users\stephen>vagrant reload
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'hashicorp/precise64' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 80 (guest) => 9090 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 4.2.0
default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
default: /vagrant => C:/Users/stephen

Then on my Windows machine I was able to visit NGINX successfully:

Stephen

Read more posts by this author.


View or post Comments