如何访问 vagrant guest servername?

How to access vagrant guest servername?

我安装了 Vagrant,按照 Hashicorp 网站的教程设置了 vagrant box,我已经设置了端口转发、具有唯一 IP 的专用网络和文件夹同步。

这是我通过 SSH 进入时的结果:

login as: vagrant
vagrant@127.0.0.1'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: 10.0.2.15
  Swap usage:   0%                IP address for eth1: 192.168.33.10

vagrant 文件在 C:\vagrant2 (Windows 10)

我有两个包含 index.html 文件的文件夹。

var/www/html 与主机中的 C:\vagrant2\html 文件夹同步(默认),我添加了另一个文件夹 var/www/html2 与主机中的 C:\vagrant2\html2 文件夹同步

流浪者文件是这样的:

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: "192.168.33.10"

在客户机中 /etc/hosts 文件是这样的(我定义了 2 个主机):

127.0.0.1 localhost
192.168.33.10 box.local
127.0.0.1 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

Apache 配置文件是这样的:

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

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

我可以通过ip地址转发访问页面: http://127.0.0.1:4567/

我可以用它的 IP 访问同一个站点: 192.168.33.10

我可以访问侦听端口 81 的第二个站点: 192.168.33.10:81

但是我需要通过我在来宾中定义的服务器名来访问。我在浏览器中输入 Windows 10 :

http://box.local

http://bebox.local

none 其中我在 Chrome 控制台中工作:

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

在客户机操作系统中,当我 ping box.local 或 box.local 时,没问题。

在主机上,ping 名称不起作用,它说找不到主机 box.local 然而 ping 本地主机确实有效

我尝试禁用 Windows 的防火墙,但没有任何改变。

您需要从您的 windows 主机修改 host 文件(它应该位于 C:\WINDOWS\system32\drivers\etc\hosts)并添加以下内容

192.168.33.10    box.local
192.168.33.10    bebox.local