apache - 如何访问vagrant guest 服务器名称?

标签 apache vagrant virtual-hosts

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

这是我通过 SSH 登录时得到的内容:

login as: vagrant
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7503141207141b01354447425b455b455b44" rel="noreferrer noopener nofollow">[email protected]</a>'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 文件是这样的:

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"

在 guest 中,/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

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

http://box.local

http://bebox.local

我在 Chrome 控制台中没有一个可以工作:

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

在客户操作系统中,当我 ping box.local 或 bebox.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

关于apache - 如何访问vagrant guest 服务器名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40886584/

相关文章:

windows - 如何在 Windows 上更新 Composer ?

vagrant - 我应该版本 .vagrant 文件夹吗

vagrant - Ansible 与 Vagrant : read inventory from Vagrantfile "extra_vars"

google-api - 我可以使用 google 来确定同一 IP 上的虚拟主机吗?

apache - 为什么 laravel homestead 不运行 Apache

java - Apache Poi,如何获取链接的工作簿?

java - 在 Wildfly 中托管多个虚拟主机/域

performance - 使用 Siege 和 AB 进行测试的准确度如何?

Vagrant-Hyper-V : The following settings shouldn't exist: customize, gui