需要 xampp 虚拟主机帮助

发布于 2024-12-02 14:48:12 字数 743 浏览 1 评论 0原文

我正在使用 XAMPP、Apache 2.2.17。我已添加虚拟主机,但我的虚拟主机和本地主机都指向同一位置。这是我在 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 的测试站点,所以这很好。但是如果我输入 localhost,它也会转到测试站点。如果我移动到测试站点之前,那么 localhost 会转到 localhost good,并且 www.domain.tld 也会转到 localhost。我尝试了 localhost 的不同设置,例如

<VirtualHost *>
<VirtualHost localhost:80>

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

I am using XAMPP, Apache 2.2.17. I have added virtual host but my virtual host and localhost both point to the same location. Here is my code in 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>

With the above code, I get testsite with www.domain.tld so that is good. But If i type localhost, it will go to testsite as well. If I move ahead of test site then localhost goes to localhost good and www.domain.tld goes to localhost too. I tried different setting for localhost as like

<VirtualHost *>
<VirtualHost localhost:80>

and removing *.domain.tld from domain.tld but nothing works. Am I missing something obvious?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

澉约 2024-12-09 14:48:12

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

<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>

My own answer: The following code fixed the problem

<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>
分分钟 2024-12-09 14:48:12

请将您的服务器名称从虚拟主机更改为本地 IP 地址,例如 127.0.0.2。

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

please change your ServerName from virtualhost to a local IP address such as 127.0.0.2.

ServerName domain.tld is an example of using "domain.com" where .tld is replaced by .com for your domain.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文