我有一个安装了 apache 的 ubuntu 服务器,服务器上的主域是子域 app.example.com,运行正常。
现在,如果我设置了 john.app.example.com,那么它也会显示 app.example.com 的网页,john.app.example.com 的 DocumentRoot 不同,但它仍然显示 app.example.com 的网页。我该如何解决这个问题,让 john.app.example.com 显示其 DocumentRoot 中的页面。
答案1
1 检查活动名称虚拟主机.打开/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 检查 Apache 配置(/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)
4测试Apache:
$ 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>