Learn Vagrant from Scratch : Networking forwarding port to host machine and other options

Now that we have provisioned our vagrant and installed nginx in it we now want our nginx to be accessed on our localhost. For that we need to make network port forwarding from virtual machine to the local machine.

Add this line in Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/precise64"
  config.vm.provision :shell, path: "provision.sh"
  config.vm.network :forwarded_port, guest: 80, host: 8000


vagrant up


vagrant run


vagrant provision

to make the necessary setting changes in your vagrant box.

After the provisioning is done we have to start the server and check if the server is working and that port 80 of virtual machine is forwarded to the port 8000 of localhost.

For testingĀ open localhost:8000 in your browser and check if the nginx message is coming in browser. If its showing the message everything is configured fine.



Gaurav Yadav

Gaurav is cloud infrastructure engineer and a full stack web developer and blogger. Sportsperson by heart and loves football. Scale is something he loves to work for and always keen to learn new tech. Experienced with CI/CD, distributed cloud infrastructure, build systems and lot of SRE Stuff.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.