如何在其他设备上访问Laravel Homestead? [英] How to access Laravel Homestead on other devices?

查看:83
本文介绍了如何在其他设备上访问Laravel Homestead?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的机器和Android设备在同一网络上.

My machine and Android devices are on the same network.

  • 机器IP:192.168.0.11
  • 运行Homestead的IP:192.168.10.10
  • Machine IP: 192.168.0.11
  • The IP where Homestead is running: 192.168.10.10

如果我在Android设备上输入192.168.0.11:8000,则只能使用一个站点.

If I enter 192.168.0.11:8000 on my Android device I can use only one site.

如何输入存储在Homestead中的所有站点?

How can I enter all sites stored in Homestead?

这是我的Homestead.yaml文件:

---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/Homestead-Projects
      to: /home/vagrant/Homestead-Projects

sites:
    - map: site1.com
      to: /home/vagrant/Homestead-Projects/Site1/public
    - map: site2.app
      to: /home/vagrant/Homestead-Projects/Site2/public

databases:
    - homestead
    - db_site1
    - db_site2

variables:
    - key: APP_ENV
      value: local

# blackfire:
#     - id: foo
#       token: bar
#       client-id: foo
#       client-token: bar

# ports:
#     - send: 93000
#       to: 9300
#     - send: 7777
#       to: 777
#       protocol: udp

这是我的hosts文件:

127.0.0.1   localhost
127.0.1.1   host

#Virtual Hosts on Homestead
192.168.10.10   site1.com
192.168.10.10   site2.com

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

推荐答案

tl; dr

您必须在远程计算机上的主机文件中为每个站点添加一行(就像在运行Homestead的服务器中一样),但是要使用服务器的IP地址.然后只需键入sitename.local:8000.

在您的情况下,服务器的IP为192.168.0.11.在此服务器中,Homestead在192.168.10.10上处理请求.因此,在服务器的主机文件中,您具有以下几行:

In your case the server's IP is 192.168.0.11. Within this server, Homestead serves requests on 192.168.10.10. So in the host file of the server you have these lines:

192.168.10.10   site1.com
192.168.10.10   site2.com

您必须将这些行复制到远程PC的主机文件中,然后将IP地址替换为服务器的IP:192.168.0.11.

You have to copy these rows to the remote PC's host file and then replace the IP address with the server's IP: 192.168.0.11.

192.168.0.11   site1.com
192.168.0.11   site2.com

根据您的操作系统,您可能必须重新启动PC或DNS服务.之后,您可以通过以下地址从远程PC访问站点:

Depending on your OS you may have to restart the PC or the DNS service. After that, you can access the sites from the remote PC in these addresses:

site1.com:8000
site2.com:8000

注意

请记住,编辑(写入)主机文件需要超级用户/管理员权限.如果您具有管理员帐户的访问权限,则在PC上很容易解决,但在移动设备上可能很复杂.对于Android,请查看以下问题:

Note

Keep in mind that editing (writing) the hosts file requires superuser/administrator permissions. This is easy to solve in a PC, if you have access to the administrator account, but can be complicated on a mobile device. For Android check out these questions:

  • Android Enthusiasts: How to edit 'etc/hosts' file?
  • Stack Overflow: How to change the hosts file on android?

这篇关于如何在其他设备上访问Laravel Homestead?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆