重定向不存在的子域

时间:2014-03-16 11:36:02

标签: apache subdomain virtualhost

我在域名 mysite.com 上运行Apache2。我有以下Apache虚拟主机:
mysite.com,admin.mysite.com,order.mysite.com,blog.mysite.com

Virtualhost mysite.com

<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com 12.123.123.123 mysitehost.ip-12-123-123.eu
ServerAdmin help@mysite.com
SuexecUserGroup mysiteuser mysiteuser
AddHandler fcgid-script .php
DocumentRoot /var/www/root/www.mysite.com

<Directory "/var/www/root/www.mysite.com">
   Options Indexes MultiViews FollowSymLinks +ExecCGI
   FCGIWrapper /var/www/root/fcgi/php-fcgi-starter .php
   Order allow,deny
   allow from all
</Directory>

LogLevel warn
ErrorLog /var/www/root/logs/error.log
CustomLog /var/www/root/logs/access.log combined
</VirtualHost>

Virtualhost admin.mysite.com (所有其他类似内容):

<VirtualHost *:80>
ServerAdmin help@mysite.com
ServerName admin.mysite.com
SuexecUserGroup mysiteuser mysiteuser
AddHandler fcgid-script .php
DocumentRoot /var/www/root/admin.mysite.com

<Directory "/var/www/root/admin.mysite.com">
   Options Indexes MultiViews FollowSymLinks +ExecCGI
   FCGIWrapper /var/www/root/fcgi/php-fcgi-starter .php
   Order allow,deny
   allow from all
</Directory>

LogLevel warn
ErrorLog /var/www/root/logs/error.log
CustomLog /var/www/root/logs/access.log combined
</VirtualHost>

我的问题是所有其他子域名(不存在)都会显示&#34; /var/www/root/admin.mysite.com"内容...例如,如果我在浏览器中输入 blaablaa.mysite.com ,我的admin.mysite.com将会打开。

请告诉我如何防止这种情况以及如何为不存在的子域设置虚拟域名。

2 个答案:

答案 0 :(得分:1)

万一有人遇到这种情况,如果OP从未真正得到答案,即使这应该是服务器故障,我也会写一个答案。您这样做的方法是让您的apache配置中的最后虚拟主机成为通配符。这是我在我的用法:

#Any subdomain that doesn't exist is caught by this
<VirtualHost *:80>
    ServerName tomg.xyz # replace with your website name. You can multiple of these virtual hosts for all of your domains on that server
    DocumentRoot /var/www/tomcatch # choose where the "404, this subdomain doesn't exist" files are
    ServerAlias *.tomg.xyz # Keeping the "*", change this to your domain
    Options FollowSymLinks
    <Directory  "/var/www/tomcatch">
        Order Allow,Deny
        Allow from all
    </Directory>
</VirtualHost>

答案 1 :(得分:0)

最简单的方法是:使用ServerName *.mysite.com设置第3个虚拟主机,并将其配置为重定向到您喜欢的位置。或者,您也可以在任何地方设置*.mysite.com DNS条目....