Apache虚拟主机无法正常运行子域

时间:2011-08-05 01:13:53

标签: apache subdomain localhost virtual-hosts

我在localhost上设置了一个我正在积极开发的网站,我想在localhost上设置一个子域名,让我的生活变得更轻松。

我将此添加到C:\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost i1.localhost:80>
    ServerAdmin dummy@localhost
    DocumentRoot "C:/xampp/htdocs/i1/"
    ServerName i1.localhost
    ServerAlias www.i1.localhost
    ErrorLog "logs/dummy-host2.localhost-error.log"
    CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>

Apache统计数据很好,但当我导航到http://localhost/时,我看到i1子域中的内容。 http://i1.localhost/可以正常工作。

然后我尝试这样做:

<VirtualHost localhost:80>
    ServerAdmin dummy@localhost
    DocumentRoot "C:/xampp/htdocs/"
    ServerName localhost
    ServerAlias www.localhost
    ErrorLog "logs/dummy-host2.localhost-error.log"
    CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>

<VirtualHost i1.localhost:80>
    ServerAdmin dummy@localhost
    DocumentRoot "C:/xampp/htdocs/i1/"
    ServerName i1.localhost
    ServerAlias www.i1.localhost
    ErrorLog "logs/dummy-host2.localhost-error.log"
    CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>

但这恰恰相反。同时localhosti1.localhost我看到来自C:/xampp/htdocs/的内容。

任何人都知道出了什么问题?

干杯。

1 个答案:

答案 0 :(得分:0)

Apache通常不喜欢另一个vhost中的vhosts文档根目录,请尝试:

DocumentRoot“C:/ xampp / htdocs /”

DocumentRoot“C:/ xampp / i1 /”