2014-09-04 274 views
0

我想用多个虚拟主机配置Apache2。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 

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

apache2 virtualhost configuration with two subdirectories接近但不帮助我。 Configuring virtual hosts on apache2在我看来似乎很相似,但它并没有给我足够的信息来解决我的问题。

我跟着已经有一些建议,但实施时,我发现这不工作(任何更多)我已阅读其他建议。我不会在这里重复这些简短的内容。

我的系统:

  • 使用Ubuntu 14.04作为客户端操作系统

步骤VirtualBox虚拟客户端

  • 我把内运行:

    并重新加载阿帕奇

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

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

    我在哪里犯了一个错误,怎么解决?

  • 回答

    0

    你究竟想要做什么?两台或多台虚拟主机在同一台服务器上?如果是这样建立在你的根文件夹2个左右目录e.g

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

    现在创建测试页两个主机来区分它们。现在创建两个独立的虚拟主机文件,首先将默认配置文件复制到域中。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 
    

    打开新的配置文件到一个编辑器,我使用纳米

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

    使内容是这样的:

    <VirtualHost *:80> 
    ServerAdmin [email protected] 
    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

    +0

    我做了你的建议so.The主要区别是虚拟主机的/var/www/html/example.com而不是我的/var/www/example.com的路径,所以没有HTML。但没有结果。还有其他建议吗? – Bernard 2014-09-04 15:23:34