需要xampp虚拟主机的帮助

问题描述 投票:5回答:3

我正在使用XAMPP,Apache 2.2.17。我添加了虚拟主机,但我的虚拟主机和localhost都指向同一位置。这是我在httpd-vhosts.conf中的代码

<VirtualHost www.domain.tld:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot "C:/xampp/htdocs/workspace/testsite"
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot "C:/xampp/htdocs/xampp"
   ServerAlias localhost
   ServerName localhost
</VirtualHost>

使用上面的代码,我得到了带有www.domain.tld的testsite,这很好。但是,如果我键入localhost,它也将转到testsite。如果我在测试站点之前移动,那么localhost会转到localhost,而www.domain.tld也会转到localhost。我尝试了localhost的不同设置

<VirtualHost *>
<VirtualHost localhost:80>

并从domain.tld中删除* .domain.tld但没有任何作用。我错过了一些明显的东西吗

xampp virtualhost
3个回答
3
投票

我自己的答案:以下代码解决了这个问题

<VirtualHost *:80> <--- * fixed the problem, apache 2.2 doc does say it must match www.domain.tld, which caused problem for other Virtual hosts
ServerName www.domain.tld
ServerAlias domain.tld 
DocumentRoot "C:/xampp/htdocs/workspace/patriot2"
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot "C:/xampp/htdocs/xampp"
   ServerAlias localhost
   ServerName localhost
</VirtualHost>

3
投票
NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot C:/xampp/htdocs
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    ServerName mydomain.local
    ServerAlias www.mydomain.local 
    DocumentRoot C:/mysite/htdocs
</VirtualHost>

-1
投票

请将您的ServerName从virtualhost更改为本地IP地址,例如127.0.0.2。

ServerName domain.tld是使用“domain.com”的示例,其中.tld由.com替换为您的域。

© www.soinside.com 2019 - 2024. All rights reserved.