Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 496
mhenry Avatar asked Jan 21 '14 06:01

mhenry


1 Answers

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.

like image 185
matt Avatar answered Nov 08 '22 22:11

matt