Apache: see named virtual hosts from LAN

假装没事ソ 提交于 2019-12-13 00:36:18

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/5922082/apache-see-named-virtual-hosts-from-lan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!