Port-forwarding
A powerful yet simple way to configure networking in Vagrant is to use port-forwarding. This does not require any advanced knowledge or configuration on your part.
Port-forwarding is the action of linking a port on your host machine to a port on the guest machine. It is as simple as that, but can be really powerful as it allows you to get up and running quickly.Â
The following are the steps to configure port-forwarding:
- Open up our Vagrantfile. We'll start with a very basic Vagrantfile by using the
ubuntu/xenial64
 box and a basic shell provision script to install the nginx web server:
- Once you've saved the Vagrantfile, run the
vagrant up
command:
- Once the box has completed installing nginx and is up and running, open your web browser and try navigating to
localhost:8080
:
- nginx should be available (possibly not on
port 8080
), but as you can see, we cannot access it. This is because we have not yet set up port-forwarding. If we access localhost from inside the Vagrant machine, we...