2011-07-26 41 views
12

我跟着这些instructions to configure subdomains for apache。我可以用http://localhost/test访问子域,虽然我无法通过http://test.localhost访问它。我怎样才能实现后者?如何在Ubuntu上为Apache2配置子域名?

# /etc/apache2/sites-available/test.localhost 
<VirtualHost *:80> 

    # Server name 
    ServerName test.localhost 

    # Document root 
    DocumentRoot /var/www/test/ 

    # Custom log file locations 
    ErrorLog /var/www/test/logs/error.log 
    CustomLog /var/www/test/logs/access.log combined 

</VirtualHost> 
+0

当你跟着说明,它应该工作。那么你错过了什么? – KingCrunch

+9

您是否已将'test.localhost'添加到您的主机文件以确保它解析为127.0.0.1? –

+0

@Marc B - 谢谢!我按照教程中的描述将子域配置为127.0.0.2。现在它工作了!请让我给你答案标志。 – JJD

回答

9

由于标记B已经正确地回答这个问题是一个/etc/hosts配置错误。正确的配置为:

# /etc/hosts 
127.0.0.1  test.localhost 
1

您链接到(从我的博客)的博客文章指示成立一个新的虚拟主机元素用127.0.0.2的IP,所以你可以很容易地创建多个子域。

你使用127.0.0.1会为一个子域工作的伟大,但如果你打算增加更多,我建议作为在后述设立新的虚拟主机设置的元素。用的Apache Tomcat 7和Ubuntu服务器的工作时