In order to "find" our virtual server in a Web browser, we need to make a map between the two host machine, and your guest server. To do this we will use a technique referred to as port forwarding. This allows any communication from the host machine (your Web browser) to be automatically redirected to the appropriate location on your guest machine (the Web server). Fortunately this is very simple to do. In this lesson we are going to map port 4567 traffic on the host machine, onto the standard Web port, 80, on the server. This means when you access Web traffic at http://localhost:4567, it will be automatically redirected to Apache on your server. It's almost like a sleight of hand magic trick where a rabbit appears in a hat, but way cooler.
By the end of this lesson you will be able to correctly configure your server's network settings so that Web pages can be viewed in a browser on your host machine.
- Edit your Vagrantfile (Vagrant configuration file to set the following properties:
- Configure port forwarding
config.vm.network "forwarded_port", guest: 80, host: 4567
- Reload the vagrant instance.
$ vagrant reload
- Log into the server, confirm Apache is running. (Hint: it's not running.)
$ curl 'http://localhost:80'
- Start Apache.
$ /etc/init.d/apache2 start
- In a Web browser, navigate to:
(Hopefully) It works!
This can sometimes be the tricky bit, especially if you already have a lot of custom network configuration. If this lesson doesn't work for you, you will need to do an audit of your system to find any software which might be interfering with the connection. We're going to limit ourselves to one VM running at a time (all the same ports). This is mostly because of the hardware limitations I expect you'll have. If your machine is more powerful, great! But we're not covering it in this video series.