Yvon Huynh Yvon Huynh - 1 year ago 156
Apache Configuration Question

How to access vagrant guest servername?

I installed Vagrant,set up vagrant box as per the tutorial of the site Hashicorp, i have set up the port forwarding, the private network with a unique IP, and folder syncing.

Here is what I have when I SSH in :

login as: vagrant
vagrant@'s password:
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-101-generic x86_64)

* Documentation: https://help.ubuntu.com/

System information as of Wed Nov 30 10:35:39 UTC 2016

System load: 0.22 Processes: 86
Usage of /: 3.7% of 39.34GB Users logged in: 0
Memory usage: 25% IP address for eth0:
Swap usage: 0% IP address for eth1:

The vagrant file is in C:\vagrant2 (Windows 10)

I have two folders that containt index.html file.

The var/www/html is synced with C:\vagrant2\html folder in the host (by default), i added another folder
The var/www/html2 is synced with C:\vagrant2\html2 folder in the host

the vagrant file is like this :

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.synced_folder "./html2", "/var/www/html2", :mount_options => ["dmode=777", "fmode=644"]
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.network :forwarded_port, guest: 80, host: 4567
config.vm.network "public_network", ip: ""

in the guest the /etc/hosts file is like this (I defined 2 hosts): localhost box.local bebox.local
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

the Apache configuration file is like this :

Listen 81
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName box.local

<VirtualHost *:81>
DocumentRoot /var/www/html2
ServerName bebox.local
ServerAlias bebox

I can access the pages via the ip address forwarding :

i can access the same site with its IP :

I can access the second site that is listening on port 81 :

However i need to access by the servername i defined in the guest. I typed in my browser in Windows 10 :



none of them work i have in Chrome console :

GET http://box.local/ net::ERR_NAME_NOT_RESOLVED

In guest operating system, when I ping box.local or bebox.local, it's okay.

On host machine, pinging the names doesn't work, it says didn't find the host box.local
however pinging even localhost does work

I tried disabling the Firewall of Windows, but doesn't change anything.

Answer Source

You need to modify the host file from your windows host machine (it should be at C:\WINDOWS\system32\drivers\etc\hosts) and add the following    box.local    bebox.local
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download