Apache:从 LAN 查看命名虚拟主机

发布于 2024-11-05 19:42:10 字数 784 浏览 0 评论 0原文

我在 Apache 上使用一些虚拟主机来加快开发速度。我的配置如下:

<VirtualHost 127.0.0.1>
    ServerName my_server.dev
    DocumentRoot "my_root"

    <Directory "my_public_files">
        AllowOverride All
        Allow from All
    </Directory>
</VirtualHost>

<VirtualHost 127.0.0.1>
    ServerName another_server.dev
    DocumentRoot "another_root"

    <Directory "other_public_files">
        AllowOverride All
        Allow from All
    </Directory>
</VirtualHost>

等等。我还将 myserver.devanother_server.dev 添加到主机文件中,因此将其中一个地址放入浏览器中会将我带到我的开发环境。

用于测试目的。我希望能够从 LAN 上的其他计算机访问这些虚拟主机。我只需输入服务器本地IP即可访问主主机,但我不知道如何访问其他虚拟主机。

我想我可以通过为每个主机分配不同的端口来做到这一点,但是一段时间后这会变得不舒服。有机会通过 LAN 上的名称访问虚拟主机吗?

I use some Virtual Hosts on Apache to speed up development. My configurations look like this:

<VirtualHost 127.0.0.1>
    ServerName my_server.dev
    DocumentRoot "my_root"

    <Directory "my_public_files">
        AllowOverride All
        Allow from All
    </Directory>
</VirtualHost>

<VirtualHost 127.0.0.1>
    ServerName another_server.dev
    DocumentRoot "another_root"

    <Directory "other_public_files">
        AllowOverride All
        Allow from All
    </Directory>
</VirtualHost>

and so on. I also add myserver.dev and another_server.dev to the hosts files, so putting one of those address into the browser takes me to my development environment.

For testing purposes. I would like to be able to access these Virtual Hosts from ohter machines on my LAN. I can access the main Host just by putting the server local IP, but I don't know how to access other Virtual Hosts.

I think I could do this by assigning a different port to each Host, but this becomes uncomfortable after a while. Any chance to access the Virtual Hosts by name on the LAN?

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

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

发布评论

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

评论(2

荒芜了季节 2024-11-12 19:42:10

您必须修改 LAN 中所有计算机上的主机文件,以便它们知道 another_server.dev 应定向到您的本地服务器。否则,dns 查找将会失败,因为该域并不真正存在。

You have to modify the hosts file on all computers in your LAN, so that they know that another_server.dev should directed to your local server. Otherwise, dns lookup will be made and fail as the domain doesn't really exists.

ペ泪落弦音 2024-11-12 19:42:10

您必须通过名称而不是 IP 访问服务器。
所以,你局域网上的机器应该知道,“another_server.dev”在哪里,因此你必须添加到主机文件行中,例如:(

10.0.0.1 another_server.dev my_server.dev

用你的机器IP替换10.0.0.1)

之后,局域网上的机器可以访问你的服务器与 http://my_server.dev

You must access the server by name, not by IP.
so, machines on you LAN should to know, where is the "another_server.dev", therefore you have to add into hosts-file line like:

10.0.0.1 another_server.dev my_server.dev

(replace 10.0.0.1 with your machine IP)

after this the machines on LAN can access your server with http://my_server.dev

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