为什么我的虚拟主机在没有域名的情况下匹配?

时间:2012-09-12 06:06:40

标签: apache

我已将httpd-vhosts.conf文件配置如下:

<VirtualHost seg.localhost:81>
    ServerAdmin my@email.com
    DocumentRoot "D:\path\to\public_html"
    ServerName http://seg.localhost
    ServerAlias http://seg.localhost
    ErrorLog "logs/seg.log"
    CustomLog "logs/seg" common
    <directory "D:\path\to\public_html">
        Options Indexes FollowSymLinks
        AllowOverride all
        Order Deny,Allow
        Deny from all
        Allow from all
    </directory>
</VirtualHost>

但是当我在浏览器中转到http://localhost:81/时,它仍然在点击该文件夹。为什么子域被忽略?

1 个答案:

答案 0 :(得分:2)

如果您使用的是基于名称的vhost,则最顶层的vhost(<VirtualHost>块的第一个实例)被视为“default” vhost,这意味着如果请求是如果主机与任何给定的<VirtualHost>都不匹配,则使用最顶层的主机。

你可以通过添加一个新的最顶层虚拟主机来解决这个问题:

<VirtualHost seg.localhost:81>
   ServerName _default_
   DocumentRoot "D:\path\to\public_html"
   <Directory "D:\path\to\public_html">
      Order Allow,Deny
      Deny from all
   </Directory>
</VirtualHost>

或者让它重定向到seg.localhost,或者你想要处理它。

相关问题