Xampp 无法加载多个站点
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该更改第二个等站点的端口号。现在所有端口地址都在端口 8080 上,如果将它们更改为其他端口号,应该没问题。
到其中 port-number 是其他端口号
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
您定义了 2 个虚拟主机以及主机文件中的名称。请首先删除主机文件中的端口号:
如果您调用 khpos.com:8080 或 demopo.com:8080,它应该到达您正确的虚拟主机。
但是:如果您调用 localhost:8080 ,它将不会匹配您的任何虚拟主机。
在这种情况下,Apache 始终输入与您的conf 文件中的端口匹配的第一个虚拟主机,而忽略其服务器名称。这是 Apache 的一个奇怪的行为 - 在我看来是一个错误。这正是你所观察到的。
出于这个原因,我总是在所有其他服务器前面放置一个虚拟虚拟服务器,它可以在一个简单的 html 文件中使用虚拟消息捕获所有不合适的请求。
只是一个提示:您已经定义了
,所以目前没有 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:
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
so there currently is no khpos.com:8080/pos because pos is part of the root unless you create another folder pos below