无法使用Vagrant转发端口访问主机上的Sinatra应用程序 [英] Unable to access Sinatra app on host machine with Vagrant forwarded ports

查看:161
本文介绍了无法使用Vagrant转发端口访问主机上的Sinatra应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ruby​​ app.rb foreman start 启动我的Sinatra应用程序后,我无法访问我的应用程序使用localhost和我的主机上的相应端口。我也可以从来宾机器的shell中的 curl 到应用程序,而在主机上卷曲请求失败。据我所知,客户机上不应该有防火墙,因为我正在使用Vagrant Ubuntu映像。

After starting my Sinatra application with both ruby app.rb and foreman start I am unable to access my application with localhost and the respective port on my host machine. I am also able to curl to the applications from within the shell of on guest machine, whereas on the host machine the curl request fails. As far as I know there shouldn't be a firewall in place on the guest machine because I'm using the Vagrant Ubuntu image.

我的Vagrantfile如下: / p>

My Vagrantfile is as follows:

Vagrant.configure('2') do |config|
  config.vm.box = 'precise32'
  config.vm.box_url = 'http://files.vagrantup.com/precise32.box'
  config.vm.network :forwarded_port, guest: 4567, host: 4567
end


推荐答案

默认情况下,在开发模式下运行时, Sinatra仅侦听localhost ,而不是 0.0.0.0 (此更改是由于安全注意事项)。

By default when running in development mode, Sinatra only listens to localhost, not to 0.0.0.0 (this change was made due to security considerations).

要允许来自任何界面的请求,请添加 set:bind,'0.0.0.0'到您的应用文件,或使用 -o 选项启动您的应用,例如 ruby​​ myapp.rb -o 0.0.0.0

To allow requests from any interface, either add set :bind, '0.0.0.0' to your app file, or start your app with the -o option, e.g. ruby myapp.rb -o 0.0.0.0.

您可以将其设置为指定的实际地址给客人,但我不知道它是否值得。

You may be able to set this to the actual address assigned to the guest, but I don’t know if it will be worth it.

这篇关于无法使用Vagrant转发端口访问主机上的Sinatra应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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