Month: November 2014

Using Vagrant when behind a proxy server

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.
On Windows:
set HTTP_PROXY= e.g. http://user:password@myproxyserver.local:8181
set HTTPS_PROXY= e.g. http://user:password@myproxyserver.local:8181

On Linux/OS X
export HTTP_PROXY= e.g. http://user:password@myproxyserver.local:8181
export HTTPS_PROXY= e.g. http://user:password@myproxyserver.local: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

Debugging a NodeJS application running on Vagrant

There are a number of debugging options open to NodeJS developers when running the server locally however, I struggled to find reliable instructions for me to debug a nodeJS application running on a Vagrant server. The following steps were required when using the server from https://github.com/semmypurewal/node-dev-bootstrap

1) Update the Vagrantfile configuration to forward ports 8080, 5858 to the host. Locate your Vagrant folder for your VM project and edit the Vagrantfile enter the following values to open the ports to your host machine.

config.vm.forward_port 8080, 8080
config.vm.forward_port 5858, 5858

2) You will need to do a vagrant halt and then a vagrant up to restart with these configuration changes.
3) Next you will need to install the node-inspector tool that allows you to debug your nodeJS application. This is done by running the following command inside your vagrant VM. sudo npm install -g node-inspector (It had to be run as sudo as it was complaining if this wasn’t done as admin)
4) Launch the application that in my situation is located at ~/app/app.js using the command node-debug --debug-port 5858 app/app.js
5) The debugger should now be available at this URL http://localhost:8080/debug?port=5858
6) The application is halted on the first statement and therefore you need to launch the debugger and click sources then continue to start the application.
7) Once it is up and running you can then set breakpoints and debug your nodeJS application running on your Vagrant server.