首页 文章

VirtualBox:如何从主机访问VM上的虚拟主机?

提问于
浏览
1

如何从主机访问在虚拟机上创建的Apache虚拟域 .

VirtualBox上的VM设置:

使用How to setup a LAMP development environment in Vagrant by Sanchit Jain Rasiya中的vagrantfile创建的VirtualBox上的

  • VM ubuntu / precise32

  • 安装了Apache / 2.2.22

  • 安装了Lynx浏览器

  • 虚拟主机/etc/apache2/sites-available/example.com

ServerAdmin webmaster@example.com ServerName example.com DocumentRoot /home/vagrant/www/example.com AllowOverride All Order allow,deny Allow from all ErrorLog“/home/vagrant/www/example.com/logs/example.com-error .log“CustomLog”/home/vagrant/www/example.com/logs/example.com-access.log“合并

从主机上的浏览器我可以访问VM的 localhost 作为 http://192.168.205.10/index.html 如何访问VM的example.com?

在主持人的 /etc/hosts 上我为example.com添加了一行

127.0.0.1   localhost
127.0.0.2   tmp.loc
127.0.0.3   temp.loc
192.168.205.10  example.com

当我尝试 http://example.com/mj.html 时,我从example.com上的Apache / 2.2.22(Ubuntu)服务器获取 404 Not Found 页面 . 端口80

在虚拟机上,我可以使用Lynx访问页面

lynx http://example.com/mj.html

这在 /home/vagrant/www/example.com/logs/example.com-access.log 文件中记录为

127.0.0.1 - - [03/Apr/2016:15:53:49 +0000] "GET /mj.html HTTP/1.0" 200 344 "-" "Lynx/2.8.8dev.9 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.12.14"

但是当我尝试从主机访问example.com时,access.log和/home/vagrant/www/example.com/logs/example.com-error.log中都没有日志 .

主机的服务器文件/ opt / lampp / logs / access_log和/ opt / lampp / logs / error_log中没有日志

1 回答

  • 0

    我有同样的问题,我一直试图从我的虚拟机vm访问我的drupal项目,但它无法正常工作 . 我在Internet上找到的解决方案之一是在VM中的hosts文件中使用outer关键字 .

    以下工作对我来说很好:

    • 在你的主机(比如一个ubuntu)类型:ifconfig,并获取wlan0的inet地址(例如:192.168.1.15)

    • 将此地址添加到virtualobox计算机中的主机文件中,并使用outer关键字

    [192.168.1.15 outer]
    

    现在,您可以通过键入wlan0的地址(例如:192.168.1.15)从虚拟机浏览器访问本地主机 .

    • 如果需要访问主机上的特定端口,请将端口号添加到地址示例192.168.1.15:8001

相关问题