Vagrant的麻烦 - " 404 - Not Found"

时间:2015-06-21 01:34:51

标签: linux vagrant virtualbox lamp portforwarding

我正在尝试使用Vagrant创建一个LAMP框。我被告知使用起来非常简单。我是网络和虚拟机的新手,对Linux / Ubuntu的经验很少。我目前正在尝试按照官方文档页面上的教程进行操作:http://docs.vagrantup.com/v2/getting-started/networking.html

我已经了解了文档中的网络文章,似乎无法使其正常运行。

现在问题是,由于我对网络和基于Linux的操作系统的经验不足,我不知道从哪里开始故障排除。我会尝试提供尽可能多的信息。

我使用最新版本的Virtualbox和Windows 8.1运行最新版本的Vagrant。

根据教程,我当前的Vagrantfile如下所示:

Vagrant.configure(2) do |config|
  config.vm.box = "hashicorp/precise32"
  config.vm.provision :shell, path: "bootstrap.sh"
  config.vm.network :forwarded_port, host: 4567, guest: 80
end

我的bootstrap.sh文件如下所示:

#!/usr/bin/env bash

apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
  rm -rf /var/www
  ln -f /vagrant /var/www
fi

当我转到http://127.0.0.1:4567时,它显示包含此消息的错误页面:

Not Found

The requested URL / was not found on this server.
===================================================
Apache/2.2.22 (Ubuntu) Server at 127.0.0.1 Port 4567

我宁愿不编辑任何配置文件,除非有解释,因为我觉得这将是一种解决方法。但无论如何,任何帮助将不胜感激。如果我需要打开一个端口,那么我该如何考虑使用XAMPP。

5 个答案:

答案 0 :(得分:12)

我有同样的问题。我试图从流浪盒中重新启动apache,我在终端上收到了警告。

vagrant@vagrant-ubuntu-trusty-64:~$ sudo service apache2 restart
 * Restarting web server apache2   

AH00112: Warning: DocumentRoot [/var/www/html] does not exist
AH00558: apache2: Could not reliably determine the server's fully qualified 
domain name, using 10.0.2.15. Set the 'ServerName' directive globally to suppress this message

创建DocumentRoot以通过创建名为/var/www/html

的目录来修复404问题

答案 1 :(得分:6)

问题出在/etc/apache2/sites-enabled 000-default文件。

Apache2指向var/www/html而流浪者示例指向var/www只需删除de / html并生成sudo service apache2 restart

答案 2 :(得分:1)

您可以从虚拟机内访问您的Web服务器吗?

例如,尝试curl localhost:80

如果未安装curl,请在Ubuntu上使用sudo apt-get install curl并重试。

另外,你检查过你的apache虚拟主机了吗? / etc / apache2 / sites-available中有000个默认文件吗?

答案 3 :(得分:1)

bootstrap.sh

中有两个问题
  1. 您需要启动网络服务。您也可以vagrant ssh手动启动它
  2. 您需要进行软链接,而不是硬链接。
  3. 因此脚本将更新为

    $ cat bootstrap.sh
    #!/usr/bin/env bash
    
    apt-get update
    apt-get install -y apache2
    if ! [ -L /var/www ]; then
      rm -rf /var/www
      ln -s /vagrant /var/www
    fi
    
    service apache2 start
    

答案 4 :(得分:0)

我已经尝试了两种有效的解决方案:

首先是更改/var/www中的文件 /etc/apache2/sites-enabled/000-default.conf 修改 DocumentRoot 而不是{{ 1}}

第二种方法是以下列方式更改 Vagrant 文件/var/www/html

bootstrap.sh

除此之外,由于某些原因,我还必须更改 Vagrantfile 中的端口转发配置,添加host_ip密钥,如下所示:

#!/usr/bin/env bash

apt-get update
apt-get install -y apache2
if ! [ -L /var/www/html ]; then
  rm -rf /var/www/html
  ln -fs /vagrant /var/www/html
fi