Unable to access Sinatra app on host machine with Vagrant forwarded ports

拟墨画扇 提交于 2019-12-04 20:17:20

问题


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.

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

回答1:


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).

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.



来源:https://stackoverflow.com/questions/21250885/unable-to-access-sinatra-app-on-host-machine-with-vagrant-forwarded-ports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!