【问题标题】:Multiple virtual hosts - This site can’t be reached Vagrant/Virtualbox多个虚拟主机 - 无法访问此站点 Vagrant/Virtualbox
【发布时间】:2016-07-03 18:18:43
【问题描述】:

我在设置多个虚拟域时遇到问题。尝试了很多解决方案,没有任何效果。 我只是错过了一些东西,但不知道是什么。至少可以说,这是一段令人沮丧的旅程。 我设置了 2 个虚拟盒子:一个用于 Laravel 环境,一个用于 Magento 环境。 他们都有同样的问题,域不起作用。这是magento:

  • 文件夹:magento
  • 虚拟域:magento.box
  • magento.conf
  • ip: 192.168.10.10

当我在浏览器 192.168.10.10 中输入时,它运行良好, 但如果我输入 magento.box 它会说明:

This site can’t be reached 
magento.box’s server DNS address could not be found.

对于 Laravel 也是如此。

Magento 虚拟盒

provision-ubuntu-15.10.sh:

#!/usr/bin/env bash

# Ubuntu 15.10 (GNU/Linux 4.2.0-34-generic x86_64) / ubuntu/wily64

# Update Ubuntu
# apt-get update

# Apache
echo "----- Provision: Installing apache..."
# apt-get install -y apache2 apache2-utils

echo "ServerName localhost" > "/etc/apache2/conf-available/fqdn.conf"
a2enconf fqdn
a2enmod rewrite
a2dissite 000-default.conf

# Folders
echo "----- Provision: Setup /var/www to point to /vagrant ..."
rm -rf /var/www
ln -fs /vagrant /var/www

# Apache / Virtual Host Setup
 echo "----- Provision: Install Host File..."
 cp /vagrant/vm_provision/hostfile /etc/apache2/sites-available/magento.conf
 a2ensite magento.conf

# Cleanup
apt-get -y autoremove

# Restart Apache
echo "----- Provision: Restarting Apache..."
service apache2 restart

流浪文件

 Vagrant.configure(2) do |config|
      config.vm.box = "ubuntu/wily64"

        config.vm.provision :shell, :path => "vm_provision/provision-ubuntu-15.10.sh"
        config.vm.network "private_network", ip: "192.168.10.10",

        owner:"vagrant", 
        group: "www-data", 
        mount_options:["dmode=770, fmode=660"]

      # VirtualBox specific settings

      config.vm.provider "virtualbox" do |vb|
        vb.gui = false
        vb.memory = "2048"
        vb.cpus = 1
      end

apache my.conf

<VirtualHost *:80>

        ServerName  www.magento.box

        DocumentRoot /var/www/magento

        # Custom log file locations
        LogLevel warn
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # Allow overrides in .htaccess file
        <Directory /var/www/>
                Options FollowSymLinks
                AllowOverride All
        </Directory>

</VirtualHost>

在主机文件中:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
127.0.0.1       localhost
127.0.0.1       www.magento.box

【问题讨论】:

    标签: dns ip vagrant virtualbox hosts


    【解决方案1】:

    为了能够输入magento.box 或任何其他本地域(例如,在外部互联网上不可用),您需要在运行浏览器的机器上修改“主机”文件。在这种情况下,您的主机(不在您的 vagrant 机器内)。该过程取决于您是否运行 Windows/OSX/Linux/等,但 here is a quick overview 来自 Wikipedia。

    你可能关心的三个:

    窗户

    %SystemRoot%\System32\drivers\etc\hosts
    

    OSX

    /etc/hosts
    

    Linux

    /etc/hosts
    

    在该文件中,您需要添加以下行以让您的操作系统知道magento.box 表示查看192.168.10.10

    192.168.10.10    magento.box
    

    请注意,您可能需要重新启动才能使其生效。另请注意,您需要 admin/sudo 权限才能编辑此文件。

    【讨论】:

    • @KorNor 相对而言,这似乎确实是问题所在,因为您的操作系统如何处理 DNS 请求存在层次结构,而 hosts 文件起着关键作用。您的主机操作系统是什么?您可以发布您的hosts 文件的全部内容吗?
    猜你喜欢
    • 2015-08-05
    • 1970-01-01
    • 1970-01-01
    • 2019-09-17
    • 1970-01-01
    • 2023-03-28
    • 2016-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多