Apache:从 LAN 查看命名虚拟主机
我在 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.dev
和 another_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须修改 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.
您必须通过名称而不是 IP 访问服务器。
所以,你局域网上的机器应该知道,“another_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:
(replace 10.0.0.1 with your machine IP)
after this the machines on LAN can access your server with http://my_server.dev