Access Apache VirtualHost from any computer on LAN?

二次信任 提交于 2019-11-29 10:08:29

问题


I have wamp setup with quite a few websites setup as virtual hosts like this in httpd.conf

<VirtualHost 127.0.0.1>
    ServerName project1.local
    DocumentRoot "c:/wamp/project1/"
</VirtualHost>

I have these input in the wamp machine's host file and I can access them just fine on that machine.

127.0.0.1 project1.local

However, when I try to put an entry on my OSX machine as (192.168.1.101 being the internal ip of the wamp machine) it won't pull the page up.

192.168.1.101 project1.local

Is there something else I need to do to make this work from other machines? Thanks!


回答1:


You either need <VirtualHost 192.168.1.101> (in addition to 127.0.0.1), or simply use <VirtualHost *> to put the VH on all addresses.




回答2:


Just add below code in your virtual host config file
In the below code,
'Client_IP' is the IP of the machine from where you want to access the directory without using any ip on the address bar, just put severname in the address bar like 'servername/'.

<VirtualHost *:80>
   ServerName servername
   DocumentRoot d:\wamp\www\dir_name                        

    <Directory "d:\wamp\www\dir_name">                             
       Order Allow,Deny
       Allow from 127.0.0.1 Client_IP
    </Directory>
 </VirtualHost>

Then, set same servername that you have used for the virtual host on apache server like,

server_ip servername 

in the client machine c:/windows/system32/drivers/etc/hosts file.



来源:https://stackoverflow.com/questions/4294235/access-apache-virtualhost-from-any-computer-on-lan

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