本地主机上的 Apache 虚拟主机

发布于 2024-10-03 23:02:33 字数 755 浏览 7 评论 0原文

我设法在本地计算机上设置虚拟热点,但现在有点碰壁了。

通常,当您在浏览器中输入 localhost/ 时,您将看到您应该看到的内容。但在我设置虚拟主机后,我输入的任何内容都会转到虚拟主机。我无法找到一种方法将虚拟主机和旧功能结合在一起。

这是我的虚拟主机文件(顺便说一句,我正在使用 xampplite)

<VirtualHost domain.eu>
    ServerName domain.eu
     DocumentRoot /www/domain

     ServerAlias *.domain.eu
</VirtualHost>

<VirtualHost domain.sk>
    ServerName domain.sk
    DocumentRoot /www/domain
</VirtualHost>

第二个文件通过 htaccess 重定向到 sk.domain.eu。当我将这 3 行添加到虚拟主机时,本地主机开始工作,但即使其他虚拟主机也转到 /www/

<VirtualHost localhost>
    DocumentRoot /www
</VirtualHost>

但每次我需要本地主机时注释/取消注释这 3 行是愚蠢的。有什么建议我怎样才能让他们两个一起工作吗?

感谢您抽出时间

I managed to set up virtual hots on my local machine, but I kinda run into a wall now.

Normally, when you type localhost/ into browser you will see what you are supposed to see. But after I have set my virtual hosts, anything I type goes to the vhost. I cant figure a way to have a virtual host AND the old functionality together.

Here is my vhost file (btw, I am using xampplite)

<VirtualHost domain.eu>
    ServerName domain.eu
     DocumentRoot /www/domain

     ServerAlias *.domain.eu
</VirtualHost>

<VirtualHost domain.sk>
    ServerName domain.sk
    DocumentRoot /www/domain
</VirtualHost>

The second one gets redirected to sk.domain.eu via htaccess. When I add these 3 lines to vhosts, localhost starts working, but even the other vhosts go to /www/

<VirtualHost localhost>
    DocumentRoot /www
</VirtualHost>

But to comment/uncomment these 3 lines everytime I need to localhost is stupid. Any advice how can I keep both of them working together?

Thanks for your time

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

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

发布评论

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

评论(2

清醇 2024-10-10 23:02:33

您确实不应该在 VirtualHost 声明中使用域名。

如果这三个虚拟主机具有不同的 IP 地址,您应该将它们各自的 IP 地址放入 VirtualHost 块中,并且永远不要提及 NameVirtualHost。

如果它们使用相同的 IP 地址,则您必须使用 NameVirtualHost,然后您必须在每个虚拟主机中以与 NameVirtualHost 声明中相同的拼写重复名称。

You really shouldn't be using domain names in the VirtualHost declarations.

If these three virtual hosts have different IP address, you should be putting their respective IP addresses into the VirtualHost blocks, and never mention NameVirtualHost.

If they use the same IP address, you must be using NameVirtualHost, and then you must, in each virtual host, repeat the name in the very same spelling that you did in the NameVirtualHost declaration.

动次打次papapa 2024-10-10 23:02:33

尝试在 VirtualHost 容器之前添加此内容:

NameVirtualHost localhost
NameVirtualHost domain.sk
NameVirtualHost domain.eu

Try adding this before the VirtualHost containers:

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