gpt4 book ai didi

ubuntu - 如何通过浏览器 ping vagrant ip 和在 vagrant 上运行的项目

转载 作者:行者123 更新时间:2023-12-04 18:32:30 25 4
gpt4 key购买 nike

我已经在 windows8 上安装了 vagrant ubuntu/precise32。我用它来运行一个rails项目。

当我启动安装在 vagrant 中的 rails 项目(即)时。它提示我 ping localhost0.0.0.0在浏览器中。在 vagrant box 上工作,怎么可能在浏览器上 ping 这个。

-deploy$ rails s
=> Booting Thin
=> Rails 4.0.3 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server Thin web server (v1.6.1 codename Death Proof) Maximum
connections set to 1024 Listening on 0.0.0.0:3000, CTRL+C to stop

因此,我无法使用 Vagrant。请让我知道如何使用浏览器查看此项目。

最佳答案

这取决于您使用的提供商。在使用 virtualbox 等最简单的情况下,您可以在 vagrant 中设置端口转发(参见:https://docs.vagrantup.com/v2/networking/forwarded_ports.html)。为了转发端口,您必须在 vagrant 配置 block 中附加以下内容:

config.vm.network "forwarded_port", guest: 3000, host: 3000

您必须运行 vagrant reload端口转发由 vagrant 设置。此外,您始终可以通过 virtualbox GUI 手动转发已经运行的 VM 上的端口(参见 http://www.howtogeek.com/122641/how-to-forward-ports-to-a-virtual-machine-and-use-it-as-a-server/ 示例)。

在更复杂的情况下,当你使用 EC2、cloudstack 等云提供商时,当 vagrant 告诉你这样的事情时:
Warning! The Cloudstack provider doesn't support any of the Vagrant
high-level network configurations (`config.vm.network`). They
will be silently ignored.

你可以通过运行 vagrant ssh-config找出机器的IP。在 vagrant 启动它并使用 ssh 隧道转发端口后,如下所示:
ssh -N -L3000:localhost:3000 -i ~/.vagrant.d/insecure_private_key vagrant@machineip

关于ubuntu - 如何通过浏览器 ping vagrant ip 和在 vagrant 上运行的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23133214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com