【问题标题】:apache2 virtualhost configurationapache2 虚拟主机配置
【发布时间】:2014-10-29 06:51:05
【问题描述】:

我想为 Apache2 配置多个虚拟主机。

似乎类似于:Apache2 weird redirection. (Default site overriding others),但该问题没有答案。

我用过:

apache2cts -S

检查配置状态,结果:

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server vbox4.dev.local (/etc/apache2/sites-enabled/000-default.conf:1)
         port 80 namevhost vbox4.dev.local (/etc/apache2/sites-enabled/000-default.conf:1)       
         port 80 namevhost www.example.com (/etc/apache2/sites-enabled/www.example.com.conf:4)
                 alias example.com

看来 Apache 知道虚拟主机的存在,但是如果我在浏览器中输入 www.example.com,则在 apache 重新加载后,仍然会显示默认的 apache 页面。

apache2 virtualhost configuration with two subdirectories 靠近但对我没有帮助。 Configuring virtual hosts on apache2 在我看来非常相似,但它没有给我足够的信息来解决我的问题。

我已经遵循了一些建议,但是在实施时我发现这不起作用(不再)我已经阅读了其他建议。为了简短起见,我不会在这里重复这些。

我的系统:

  • 在 Virtualbox 客户端中运行
  • 使用 Ubuntu 14.04 作为客户端操作系统

我采取的步骤:

并重新加载了apache

  • 结果:浏览器指向默认本地主机“Apache2 Ubuntu 默认页面” 但不是我预期的该域的小型 index.html 文件。

/var/log/apache2/error.log 没有显示错误。

我在哪里犯了错误,如何解决?

【问题讨论】:

    标签: apache ubuntu virtualhost


    【解决方案1】:

    你到底想做什么?同一台服务器上的两个或多个虚拟主机?如果是这样,在您的根文件夹上创建 2 个左右的目录,例如

    mkdir /var/www/html/example.com
    mkdir /var/www/html/anotherhost.com
    

    现在为两个主机创建测试页面以区分它们。现在创建两个单独的虚拟主机文件,首先将默认配置文件复制到 domain.conf 中:

    sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
    
    sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/anotherhost.com.conf
    

    在编辑器中打开你的新配置文件,我使用 nano

    sudo nano /etc/apache2/sites-available/example.com.conf
    

    使内容看起来像:

    <VirtualHost *:80>
     ServerAdmin admin@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/html/example.com
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    

    对另一台主机执行相同操作并启用虚拟主机

    sudo a2ensite example.com.conf
    sudo a2ensite anotherhost.com.conf
    

    重启apache

    【讨论】:

    • 我这样做了。与您的建议的主要区别是虚拟主机的路径在 /var/www/html/example.com 而不是我的 /var/www/example.com ,所以没有 html .但没有结果。还有其他建议吗?
    猜你喜欢
    • 2014-10-23
    • 1970-01-01
    • 2012-03-18
    • 2017-07-23
    • 2018-07-06
    • 1970-01-01
    • 2015-10-06
    • 2023-03-04
    • 2016-09-11
    相关资源
    最近更新 更多