Apache2虚拟主机坏了; 在子域上显示默认的index.html,但在www.subdomain上正确的内容

我已经将Linodeconfiguration为Apache 2.2.14的Ubuntu 10.04.2 Web服务器。

我总共有4个站点,全部在/etc/apache2/sites-available下定义为虚拟主机。 所有站点几乎都是相同的克隆进行configuration。 而所有的网站,但我最后的工作成功。

 default: (www.)exampleadnetwork.com (www.)example.com reseller.example.com trouble: client1.example.com 

当我访问client1.example.com网站时,我不断收到此页面:

有用!

这是此服务器的默认网页。

networking服务器软件正在运行,但尚未添加内容。

在我的ports.conf文件中,我将NameVirtualHost正确设置为端口80上的IP地址。

如果我访问“www.sub.example.com”别名的网站工作! 如果我在没有www的情况下访问它,我会看到上面贴出的“It Works”摘录。 即使apache2ctl -S显示我的虚拟主机文件parsing正确,并被添加到混合。

我的虚拟主机configuration文件如下:

 <VirtualHost 127.0.0.1:80> ServerAdmin [email protected] ServerName client1.example.com ServerAlias client1.example.com www.client1.example.com DocumentRoot /srv/www/client1.example.com/public_html/ ErrorLog /srv/www/client1.example.com/logs/error.log CustomLog /srv/www/client1.example.com/logs/access.log combined <directory /srv/www/client1.example.com/public_html/> Options -Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </directory> </VirtualHost> 

其他网站是以下的变体:

 <VirtualHost 127.0.0.1:80> ServerAdmin [email protected] ServerName example.com ServerAlias example.com www.example.com DocumentRoot /srv/www/example.com/public_html/ ErrorLog /srv/www/example.com/logs/error.log CustomLog /srv/www/example.com/logs/access.log combined </VirtualHost> 

唯一不同的地方是另一个子域名:

 <VirtualHost 127.0.0.1:80> ServerAdmin [email protected] ServerName reseller.example.com ServerAlias reseller.example.com DocumentRoot /srv/www/reseller.example.com/public_html/ ErrorLog /srv/www/reseller.example.com/logs/error.log CustomLog /srv/www/reseller.example.com/logs/access.log combined </VirtualHost> 

文件名是没有www的FQDN。 字首。

我遵循这个build议 ,但仍然无法正确访问子域。

我遇到了完全相同的问题,最终解决了这个问题的时候,我把apache中的默认网站与启用网站的链接断开连接:

 sudo unlink /etc/apache2/sites-enabled/000-default 

这样做后,我的所有网站都正确显示。 我看到这个问题是相当古老的,但希望这可以帮助别人。

其他海报的解决scheme将做到这一点。

显示您的“它工作”,因为所有您的Virtuall主机匹配到本地主机。 如果你打电话给“client1.example.com”,apache会跳过本地主机的Vhosts,如果没有匹配的Vhost,它将使用默认的configuration。

做其他海报告诉的(把你的虚拟主机改成<VirtualHost *:80><VirtualHost *> ,把你的默认虚拟主机改成你喜欢的文档根目录。

不要忘记:即使你正确地定义了你的虚拟主机,如果有人请求你的服务器没有主机名(例如通过IP地址),服务器也会调用默认的虚拟主机。

尝试一下,不要在ServerName和ServerAlias中有重复的条目。

例如:

 <VirtualHost *:80> ServerAdmin [email protected] ServerName sub.example.com ServerAlias www.sub.example.com DocumentRoot /srv/www/sub.example.com/public_html/ ErrorLog /srv/www/sub.example.com/logs/error.log CustomLog /srv/www/sub.example.com/logs/access.log combined <directory /srv/www/sub.example.com/public_html/> Options -Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </directory> 

一些build议:

  • <VirtualHost 127.0.0.1:80>更改为<VirtualHost *:80>
  • 您是否放置了NameVirtualHost *:80configuration?
  • 在每个DocumentRoot下放置一个index.html文件,显然每个文件都有不同的消息来标识你在哪里访问
  • 尝试从本地主机访问,如果可能尝试从另一个位置

你检查过你的网站的DNSparsing吗?

(www。)sub.example.com都parsing到相同的机器(即使不同的地址)?

检查他们两个的日志,看看你的所有访问权限是否在正确的服务器(configuration)上,或者他们是否违反默认值,因为“It Works!” 是默认configuration的默认页面。

如果他们正在默认情况下,你必须确定这是为什么…configuration之间有什么区别。 如前所述,尝试更改IP,因为Apache会将configuration绑定到VirtualHost指令中指定的特定IP地址。

NameVirualHostconfiguration不正确。 摆脱127.0.0.1 ,并使*通配符。 当你明确地设置127.0.0.1 ,将你的机器上的所有连接绑定到该configuration。 NameVirualHost需要*的通配符:

 <VirtualHost *:80> ServerAdmin [email protected] ServerName client1.example.com ServerAlias client1.example.com www.client1.example.com DocumentRoot /srv/www/client1.example.com/public_html/ ErrorLog /srv/www/client1.example.com/logs/error.log CustomLog /srv/www/client1.example.com/logs/access.log combined <directory /srv/www/client1.example.com/public_html/> Options -Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </directory> </VirtualHost> The other sites are variations of: <VirtualHost *:80> ServerAdmin [email protected] ServerName example.com ServerAlias example.com www.example.com DocumentRoot /srv/www/example.com/public_html/ ErrorLog /srv/www/example.com/logs/error.log CustomLog /srv/www/example.com/logs/access.log combined </VirtualHost> The only site the differs is the other subdomain: <VirtualHost *:80> ServerAdmin [email protected] ServerName reseller.example.com ServerAlias reseller.example.com DocumentRoot /srv/www/reseller.example.com/public_html/ ErrorLog /srv/www/reseller.example.com/logs/error.log CustomLog /srv/www/reseller.example.com/logs/access.log combined </VirtualHost> 

另外,确保NameVirtualHost设置如下。 在Ubuntu下我的设置,你会看到在这个文件中的行: /etc/apache2/ports.conf

 NameVirtualHost *:80 Listen 80