使用 Apache 在本地网络上托管网站
我目前在我的机器上使用 Apache 在本地测试 PHP 网站。我只是想知道如何允许连接到本地网络的计算机访问本地计算机上托管的网站。
I currently use Apache on my machine to test PHP websites locally. I was just wondering how I can allow computers connected to my local network to access the website hosted on my local machine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果仅通过 IP,本地网络上的计算机应该能够访问您的计算机(假设您没有防火墙阻止端口 80 (HTTP))。
完成后,您可以在 httpd.conf 中设置虚拟主机(查看在最底部,应该有一些示例指令来帮助您开始)
如果您希望计算机能够访问您计算机上的多个不同网站,那么您需要在 VirtualHost 设置中创建本地/假域名并还欺骗其 .hosts 文件中的 dns(Windows 计算机上的 c:\windows\system32\drivers\etc\hosts)。
本质上,您要做的就是告诉他们的计算机可以访问网站 www.testsite.local。 IP地址xxxx,然后你的VirtualHost指令将告诉apache网站www.testsite.local可以在/home/user/public_html/找到
Machines on your local network should be able to access your machine, if only by IP (assuming you don't have a firewall blocking port 80 (HTTP).
Once that's done, you can setup Virtual Hosts in your httpd.conf (look at the very bottom, there should be some sample directives to get you started).
If you want the machines to be able to access multiple different websites on your machine, then you'll need to create local/fake domain names in your VirtualHost setup and also spoof the dns in their .hosts files (c:\windows\system32\drivers\etc\hosts on windows machines).
Essentially what you'll be doing is telling their machines that the website www.testsite.local can be reached at the ip address x.x.x.x, and then your VirtualHost directives will tell apache that the website www.testsite.local can be found at /home/user/public_html/
如果您在初始配置期间启用了这些设置,则只需将托管 Apache 的计算机的 IP 地址输入另一台计算机上的 Web 浏览器即可。
检查端口是否打开并且没有防火墙阻止应用程序。
Providing you enabled the settings during the initial configuration, it should just be a case of entering the IP address of the computer hosting Apache into a web browser on another computer.
Check that the ports are open and no firewalls are blocking the application.