宅基地无法远程访问第二个站点 [英] Homestead cant access second site remotely

查看:197
本文介绍了宅基地无法远程访问第二个站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以很好地设置一个站点,但是不能远程访问第二个站点:

I have one site setup fine, but the second can't be accessed remotely:

我的YAML:

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

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

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

sites:
    - map: app.app
      to: /home/vagrant/sites/app1/public
    - map: app2.app
      to: /home/vagrant/sites/app2/public
      port: 8100

ports:
    - host: 81
    - guest: 8100

我可以使用我的IP轻松访问第一个站点-http://192.168.0.5/,但是第二个站点不能共享相同的端口,因此我添加了81 -> 8100.

I can access the first site using my IP easily - http://192.168.0.5/ but the second one cannot share the same port, so I've added 81 -> 8100.

当我尝试重新置放我的宅基地流浪者盒子时,它说: 本机的配置中有错误.请修正 出现以下错误,然后重试:

When I try to reprovision my homestead vagrant box it says: There are errors in the configuration of this machine. Please fix the following errors and try again:

vm:
* Forwarded port definitions require a "host" and "guest" value
* Ports to forward must be 1 to 65535
* Ports to forward must be 1 to 65535

有什么想法吗?

推荐答案

服务 xip.io 可以缩短工作时间这个的.方法如下:

The service xip.io can make short work of this. Here's how:

作为示例,我有以下Homesite应用程序设置"rentmanager.test".这是我在Homestead上配置的第一个应用程序,因此它是默认路由.要从我的本地网络访问此文件,我要做的只是去:

As an example, I have the following Homesite app setup, 'rentmanager.test'. This is the first application I provisioned on Homestead, so it's the default route. To access this from my local network, all I have to do is go to:

http://rentmanager.test.192.168.5.124.xip.io:8000

此处为"rentmanager.test".是我在Homestead上的Laravel应用程序的名称,即"192.166.5.124".是我在本地网络上的IP地址,"xip.io:8000"是重定向服务域,也是访问Homestead设置的默认路由之外访问应用程序(8000)所需的端口.

Where 'rentmanager.test.' is the name of my Laravel application on Homestead, '192.166.5.124.' is my IP address on the local network, 'xip.io:8000' is the redirect service domain and the needed port to access the app (8000) outside of the default routing that Homestead sets up.

现在,此方法对于您提供的第一个站点开箱即用,但是如果我们有多个站点,该怎么办?这需要更多的腿部动作.假设我们要访问另一个名为"sitescanner.test"的应用程序.如果我尝试使用新的应用程序URL访问与上面相同的URL,您将看到我仍在使用第一个应用程序!让我们也解决它.

Now, this works fine out of the box with the first site you provision, but what happens if we have more than one site? That requires a little more legwork. Let's assume we've got a second app called 'sitescanner.test' that we want to access. If I try to access the same URL above with the new app URL, you'll see I'm still served the first application! Let's resolve that as well.

首先,您将需要在主机文件中添加其他规则.因此,假设我们的新应用程序名为"sitescanner.test":

First, you're going to need to add an additional rule to your hosts file. So, assuming our new app is called 'sitescanner.test':

# Vagrant Sites External Access

192.168.10.10 sitescanner.test.192.168.5.124.xip.io

一旦完成,我们就必须更新Homestead中的配置脚本以创建正确的虚拟主机条目,以便Homestead知道如何路由请求.为此,我们将编辑您的Homestead.yaml.在"sites:"指令下:

Once that's in place then we have to update the provisioning scripts in Homestead to create the correct virtual host entries so Homestead knows how to route the request. To do that, we'll edit your Homestead.yaml. Under the 'sites:' directive:

- map: sitescanner.test
  to: /home/vagrant/Code/sitescanner/public   
- map: sitescanner.test.192.168.5.124.xip.io
  to: /home/vagrant/Code/sitescanner/public 

完成后,只需无用停止"(如果它已经在运行),然后无用--provision",您应该可以从以下位置访问您的网站

Once this is complete, simply 'vagrant halt' (if it's already running), then 'vagrant up --provision' and you should be able to access your site from

http://sitescanner.test.192.168.5.124.xip.io:8000

您网络上的任何地方!希望这可以帮助.

Anywhere on your network! Hope this helps.

在考虑这一点时,需要对此配置做最后的考虑:

While I'm thinking about it, there is a final consideration for this configuration:

  • 如果可能,您可能想在主机上设置静态IP地址.如果通过DHCP为您分配了动态IP地址,那么在您分配了新IP时,此配置有可能(很可能)最终中断.

这篇关于宅基地无法远程访问第二个站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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