【发布时间】:2016-07-23 02:45:58
【问题描述】:
如何从主机访问在虚拟机上创建的 Apache 虚拟域。
VirtualBox 上的虚拟机设置:
- VirtualBox 上的 VM ubuntu/precise32 使用来自 How to setup a LAMP development environment in Vagrant by Sanchit Jain Rasiya 的 vagrantfile 创建
- 已安装 Apache/2.2.22
- 已安装 Lynx 浏览器
-
虚拟主机 /etc/apache2/sites-available/example.com
ServerAdmin webmaster@example.com 服务器名称 example.com DocumentRoot /home/vagrant/www/example.com 允许覆盖所有 命令允许,拒绝 允许所有人 错误日志“/home/vagrant/www/example.com/logs/example.com-error.log” CustomLog "/home/vagrant/www/example.com/logs/example.com-access.log" 合并
从主机上的浏览器我可以访问虚拟机的localhosthttp://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 时,我从 Apache/2.2.22 (Ubuntu) 服务器的 example.com 端口 80 获得了 404 Not Found 页面
在虚拟机上我可以使用 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 中都没有日志
主机的Server文件/opt/lampp/logs/access_log和/opt/lampp/logs/error_log中没有日志
【问题讨论】:
标签: apache2 virtualbox virtualhost