Ubuntu的Apache的子域指向主域

我有一个Ubuntu的服务器与Apache安装,服务器上的主域是子域app.example.com,这是正常工作。

现在,如果我设置了john.app.example.com,那么也显示app.example.com的网页,john.app.example.com的DocumentRoot是不同的,但它仍然显示app.example的网页.COM。 我该如何解决这个问题,所以john.app.example.com会显示DocumentRoot中的页面。

1检查活动的NameVirtualHost 。 打开/etc/apache2/ports.conf文件:

NameVirtualHost *:80 

2检查DNS

 # ping app.local PING localhost.localdomain (127.0.0.1) 56(84) bytes of data. # ping john.app.local PING localhost.localdomain (127.0.0.1) 56(84) bytes of data. 

3检查Apacheconfiguration(/ etc / apache2 / sites-enabled / 000-default):

 <VirtualHost *:80> ServerName app.local DocumentRoot /var/www <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost> <VirtualHost *:80> ServerName john.app.local DocumentRoot /var/www/john </VirtualHost> $ sudo apache2ctl configtest Syntax OK $ sudo apache2 -S VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: *:80 is a NameVirtualHost default server app.local (/etc/apache2/sites-enabled/000-default:1) port 80 namevhost app.local (/etc/apache2/sites-enabled/000-default:1) port 80 namevhost john.app.local (/etc/apache2/sites-enabled/000-default:12) 

4testingApache:

 $ curl http://john.app.local john $ curl http://app.local <html><body><h1>It works!</h1> <p>This is the default web page for this server.</p> <p>The web server software is running but no content has been added, yet.</p> </body></html>