How to provision nginx vhosts on Vagrant vm?

by Jake Wilson   Last Updated April 15, 2019 11:00 AM

I have a Ubuntu VM machine I'm running through Vagrant with nginx installed. It's pretty easy to ssh into the VM and setup a new nginx vhost whenever I need one. But what is the best practice for setting up nginx vhosts via Vagrant provisioning, or maybe using Puppet? Essentially I imagine some sort of config file(s) that sit in my host folder and when I provision, it parses these config files and creates a new vhost for me on the VM.

Tags : vagrant


Answers 2


Have a look at https://www.vagrantup.com/docs/provisioning/ansible.html particularly https://www.vagrantup.com/docs/provisioning/ansible_local.html

With this you will be able to set anything you need on the vagrant VM.

sebastienvg
sebastienvg
July 26, 2016 15:10 PM

There is a vagrant plugin - hostupdater. It can automatically update /etc/hosts and add virtual hosts pointing to your guest machine

Vagrant file configuration example:

config.vm.network :private_network, ip: "192.168.3.10"
config.vm.hostname = "www.testing.de"
config.hostsupdater.aliases = ["alias.testing.de", "alias2.somedomain.com"]
Niv-Mizzet
Niv-Mizzet
January 18, 2017 09:59 AM

Related Questions


Vagrant duplicate IP

Updated October 23, 2015 06:00 AM

How can I move my deploy key into vagrant?

Updated June 02, 2017 16:00 PM

Remote Vagrant Dev Server

Updated September 03, 2017 12:00 PM

vagrant ssh -c logs me in withuot any reason

Updated January 10, 2018 21:00 PM