Ubuntu-添加apache子域

Ubuntu-添加apache子域,apache,.htaccess,ubuntu,hosts,Apache,.htaccess,Ubuntu,Hosts,我有一个网站www.site.com,site.com在我的Ubuntu服务器上运行良好 我现在想添加一个子域sub.site.com,以便两者在同一台服务器上工作 这是apachectl-S显示的内容: $ apachectl -S VirtualHost configuration: 127.0.0.1:80 is a NameVirtualHost default server www.site.com (/etc/apache2/sites-enabled/

我有一个网站www.site.com,site.com在我的Ubuntu服务器上运行良好

我现在想添加一个子域sub.site.com,以便两者在同一台服务器上工作

这是apachectl-S显示的内容:

$ apachectl -S
VirtualHost configuration:
127.0.0.1:80           is a NameVirtualHost
     default server www.site.com (/etc/apache2/sites-enabled/site.com.conf:1)
     port 80 namevhost www.site.com (/etc/apache2/sites-enabled/site.com.conf:1)
             alias site.com
     port 80 namevhost sub.site.com (/etc/apache2/sites-enabled/sub.site.com.conf:1)
在/etc/hosts中,我有:

127.0.0.1 localhost
127.0.0.1 sub.site.com 
127.0.0.1 www.site.com
但当我尝试访问sub.site.com时,我会被重定向到www.site.com

我不知道我还缺少什么

任何帮助都将不胜感激

--更新--

我的站点启用了配置文件:

site.conf

<VirtualHost www.site.com:80>
ServerName www.site.com
ServerAlias site.com
ServerAdmin info@site.com
DocumentRoot /home/ubuntu/site
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/home/ubuntu/site">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    Require all granted
</Directory>
</VirtualHost>
以及子域sub.conf

<VirtualHost sub.site.com:80>
ServerName sub.site.com
ServerAdmin info@site.com
DocumentRoot /home/ubuntu/sub
ErrorLog ${APACHE_LOG_DIR}/error_sub.log
CustomLog ${APACHE_LOG_DIR}/access_sub.log combined
</VirtualHost>

您重新启动了apache服务吗?您的实际VHOST文件是什么样子的?也许可以把这个问题加上。还可以使用其他浏览器进行测试,以确保缓存问题。我已更新了说明。。。谢谢建议不要在Vhost指令中使用主机名。使用IP地址或*或权限。这一改变是另一个绝望的失败解决方案。