Xampp 无法加载多个站点

发布于 2025-01-13 12:40:15 字数 822 浏览 4 评论 0原文

我正在使用 xampp 服务器开发一个项目。我有不止一个项目。因此,为此,我设置了如下所示的 httpd-vhosts

<VirtualHost *:8080>
  
  ServerName khpos.com
  ServerAlias www.khpos.com

  DocumentRoot "D:/xampp/htdocs/pos"


<Directory "D:/xampp/htdocs/pos">
   Require all granted
</Directory>

</VirtualHost>
 #my second site
<VirtualHost *:8080>

ServerName demopos.com
ServerAlias www.demopos.com

 DocumentRoot "D:/xampp/htdocs/demopos"


<Directory "D:/xampp/htdocs/demopos">
   Require all granted
</Directory>

</VirtualHost>

每当我尝试点击 localhost:8080/demopos 时,它都会重定向到 .../pos >

主机文件

127.0.0.1:8080      khpos.com
127.0.0.1:8080      demopos.com

如何设置

任何帮助将不胜感激

I am working on a project using xampp server. I have more than one project. So for this I have set my httpd-vhosts like below

<VirtualHost *:8080>
  
  ServerName khpos.com
  ServerAlias www.khpos.com

  DocumentRoot "D:/xampp/htdocs/pos"


<Directory "D:/xampp/htdocs/pos">
   Require all granted
</Directory>

</VirtualHost>
 #my second site
<VirtualHost *:8080>

ServerName demopos.com
ServerAlias www.demopos.com

 DocumentRoot "D:/xampp/htdocs/demopos"


<Directory "D:/xampp/htdocs/demopos">
   Require all granted
</Directory>

</VirtualHost>

Whenever I try to hit localhost:8080/demopos it's redirecting towards .../pos

hosts file

127.0.0.1:8080      khpos.com
127.0.0.1:8080      demopos.com

How to set it

Any help would be highly appreciated

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

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

发布评论

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

评论(2

稍尽春風 2025-01-20 12:40:15

您应该更改第二个等站点的端口号。现在所有端口地址都在端口 8080 上,如果将它们更改为其他端口号,应该没问题。

其中 port-number 是其他端口号

127.0.0.1:8080               khpos.com
127.0.0.1:{port-number}      demopos.com

You should change the portnumbers of the second etc. sites. Now all port addresses are on port 8080, if you change those to an other port number you should be fine.

<VirtualHost *:8080> to <VirtualHost *:{port-number}>

Where port-number is an other port-number

127.0.0.1:8080               khpos.com
127.0.0.1:{port-number}      demopos.com
弥枳 2025-01-20 12:40:15

您定义了 2 个虚拟主机以及主机文件中的名称。请首先删除主机文件中的端口号:

ServerName khpos.com
ServerName demopos.com
127.0.0.1    khpos.com
127.0.0.1    demopos.com

如果您调用 khpos.com:8080 或 demopo.com:8080,它应该到达您正确的虚拟主机。

但是:如果您调用 localhost:8080 ,它将不会匹配您的任何虚拟主机。

在这种情况下,Apache 始终输入与您的conf 文件中的端口匹配的第一个虚拟主机,而忽略其服务器名称。这是 Apache 的一个奇怪的行为 - 在我看来是一个错误。这正是你所观察到的。

出于这个原因,我总是在所有其他服务器前面放置一个虚拟虚拟服务器,它可以在一个简单的 html 文件中使用虚拟消息捕获所有不合适的请求。

只是一个提示:您已经定义了

DocumentRoot "D:/xampp/htdocs/pos"

,所以目前没有 khpos.com:8080/pos 因为 pos 是根目录的一部分,除非您在下面创建另一个文件夹 pos

you have 2 virtual hosts defined and also the names in hosts file. Please first remove the port numbers in the hosts file:

ServerName khpos.com
ServerName demopos.com
127.0.0.1    khpos.com
127.0.0.1    demopos.com

if you call khpos.com:8080 or demopo.com:8080 it should reach your correct virtual hosts.

But: if you call localhost:8080 it will match none of your virtual hosts.

In that case Apache always enters the first virtual host matching the port that you have in your conf file ignoring its server name. That is a strange behavior of Apache - in my opinion a bug. It is exactly what you observe.

For that reason I always place a dummy virtual server in front of all others that can catch all non fitting requests with a dummy message in a simple html file.

Just a hint: you have defined

DocumentRoot "D:/xampp/htdocs/pos"

so there currently is no khpos.com:8080/pos because pos is part of the root unless you create another folder pos below

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