Saturday, 20 June 2015

[Partial Solution] Unable to access rails server on a VirtualBox guest

I've been having problems accessing my Linux VirtualBox guest from my windows machine.

The solution turns out to be fairly simple and is explained in more depth here. However this only applies when ran from the command line, running via Guard this solution doesn't work.

A change to the default host in the rails server means that the server will only listen for requests from localhost.

The solution is to start the server with rails server -b 0.0.0.0 to get it to listen to all interfaces.

I edited my config/boot.rb to say:

require "rails/commands/server"
module Rails
class Server
def default_options
super.merge({
:Host => 'my-host.com',
:Port => 3000,
:environment => (ENV['RAILS_ENV'] || "development").dup,
:daemonize => false,
:debugger => false,
:pid => File.expand_path("tmp/pids/server.pid"),
:config => File.expand_path("config.ru")
})
end
end
end

Now I don't need to remember about including the switch.

This doesn't help when running guard, a temporary hack is to use
rails server -b 0.0.0.0 & guard
but this is a bit of a klunky solution. I've posted a question in StackOverflow

No comments:

Post a Comment