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

Learn Vagrant from Scratch : Networking forwarding port to host machine and other options
4.33 (86.67%) 6 votes

  Less than a minute

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
end

Run

vagrant up

or

vagrant run

or

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 a Full Stack Web Developer and Blogger. Sportsperson by heart and loves football. He has experience with various frameworks in php, python and javascript. Loves to explore new frameworks and evolve with the trending technology.

Leave a Reply

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