0

We are trying to use nginx as a proxy/router thing so we can redevelop parts of a large monolith web site. The idea is to have developers run nginx in a vagrant created vm that will route requests either to a new site or the original monolith. All of the sites are in windows on the host machine.

I need to setup the hosts file on the guest os so that it can route to the host machine. Currently the host web site is running on localhost and the guest os thinks that it is also on 127.0.0.1 so the routing from nginx fails.

I need to have vagrant update the guest host file with the site name and the ip of the host machine.

I see a thing called vagrant host manager but ... Im comletely confused by this network stuff.

Thanks

UPDATE: I have this in the vagrantfile to setup nginx.

config.vm.provision "shell", inline: <<-SHELL1
    apt-get -y update
    apt-get -y install nginx   
    apt-get -y install curl

  SHELL1

  config.vm.provision "shell", run:"always", inline: <<-SHELL2
    echo "Configuring Nginx"
    cp /vagrant_data/nginx.conf /etc/nginx/sites-available/nginx_vhost
    ln -s /etc/nginx/sites-available/nginx_vhost /etc/nginx/sites-enabled/
    rm -rf /etc/nginx/sites-available/default
    service nginx restart

  SHELL2

And I have the following to update my host hosts file (windows):

  config.hostmanager.enabled = true
  config.hostmanager.manage_host = true
  config.hostmanager.manage_guest = false
  config.hostmanager.ignore_private_ip = false
  config.hostmanager.include_offline = true
Jonesie
  • 6,997
  • 10
  • 48
  • 66
  • do you know what you need to add to the host file ? just have a shell script to append the info to your file. – Frederic Henri Nov 16 '16 at 21:03
  • Yeah I do, but I want to provide this to other devs so I cant hard code my own ip address in there. I think a shell script would work fine - just dont know how to get that into the vagrantfile. – Jonesie Nov 16 '16 at 22:07
  • Oh, just found this: http://stackoverflow.com/questions/19917148/tell-vagrant-the-ip-of-the-host-machine – Jonesie Nov 16 '16 at 22:15

1 Answers1

0

Ok solved as per the update above plus using this to update the guest OS hosts:

sudo echo "10.0.2.2 site.name" | sudo tee -a /etc/hosts

10.0.2.2 is the hard-coded virtualbox ip for the host. Other variations using sed gave errors.

Jonesie
  • 6,997
  • 10
  • 48
  • 66