Trouble with Vagrant - “404 - Not Found”

前端 未结 5 1136
逝去的感伤
逝去的感伤 2021-02-09 10:47

I am attempting to make a LAMP box using Vagrant. I have been told that it is quite simple to use. I am completely new to networks and virtual machines and have very little expe

相关标签:
5条回答
  • 2021-02-09 11:16

    I had same problem. I tried to restart apache from the vagrant box, I got following warning on my terminal.

    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
    

    Create a DocumentRoot to fix the 404 issue by creating a directory called /var/www/html

    0 讨论(0)
  • 2021-02-09 11:36

    The issue is on /etc/apache2/sites-enabled 000-default file.

    Apache2 is pointing to var/www/html and vagrant example to var/www just remove de /html and make a sudo service apache2 restart.

    0 讨论(0)
  • 2021-02-09 11:36

    Can you access your web server from inside your virtual machine ?

    For example, try curl localhost:80

    if curl is not installed, use sudo apt-get install curl on Ubuntu and try again.

    Also, have you checked your apache virtual hosts ? Is there a 000-default file in /etc/apache2/sites-available ?

    0 讨论(0)
  • 2021-02-09 11:37

    I've experimented two working solutions:

    The first is to change the file /etc/apache2/sites-enabled/000-default.conf modifing DocumentRoot in /var/www instead of /var/www/html

    The second is to change the Vagrant file bootstrap.sh in the following way:

    #!/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
    

    Beside that, for some reason I've had to change also the configuration of port forwarding in the Vagrantfile, adding the host_ip key, like this:

    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, host_ip: "127.0.0.1"
    end
    
    0 讨论(0)
  • 2021-02-09 11:37

    There are two issues in bootstrap.sh

    1. You need start the web service. You can also vagrant ssh to manually start it
    2. You need make soft link, not hard link.

    So the script will be updated as

    $ 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
    
    0 讨论(0)
提交回复
热议问题