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.

3 Answers 3


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.

  • Anible.com seems to be some sort of pay service. Where do I find Ansible playbooks? Jul 26, 2016 at 18:52
  • Ansible sales Ansible-Tower (enterprise version with UI), ansible itself is free. Regarding playbooks you have to write them or you can download some at galaxy.ansible.com Jul 26, 2016 at 18:54

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: ""
config.vm.hostname = "www.testing.de"
config.hostsupdater.aliases = ["alias.testing.de", "alias2.somedomain.com"]

You can use a configuration management tool. Just write a template for nginx, apply variables as needed, reload nginx, and Bob's your uncle. Ansible is extremely easy to use, you can use ansible-galaxy to pull geerlingguy.nginx, which is a role that easily configures the basics for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.