0

Rails -v 4.1.1 Ruby -v 2.2.1

I have 2 rails applications on one AWS EC2 instance. One app, I am able to startup on Webrick with:

rails server

I am then able to access the application remotely at the following URL:

 http://[public_ip]:3000

The second app, I have to provide the -b and -p options. Without the options accessing the application at http://[public_ip]:3000 gives me:

This webpage is not available
connection attempt to [public_ip] was rejected. The website may be down, or your network may not be properly configured.

The only server startup otions that works for the second app is:

rails s -b 0.0.0.0 -p 3000

I am then able to access the second app at http://[public_ip]:3000. The second app is a brand new app I created on the server. The first app is code I checked out from an existing app. How do I make the second app behave the same as the first app?

sotn
  • 1,833
  • 5
  • 35
  • 65

1 Answers1

0

Before Rails 4.2 default binding host for rails s command was 0.0.0.0. Starting from Rails 4.2 it's localhost. So it's no wonder you having this issue with the new app.

If you want your new app to start on 0.0.0.0 automatically, include this into config/boot.rb:

require 'rails/commands/server'
module Rails
  class Server
    def default_options
      super.merge(Host:  '0.0.0.0', Port: 3000)
    end
  end
end

Based on this answer.

Community
  • 1
  • 1
dimakura
  • 7,575
  • 17
  • 36
  • I edited my post to show versions. Given that I'm working on a version before 4.2, server startup with no options should work. Also, the boot.rb for the first/existing app does not have the code snippet you provide yet I can access it on the default IP and port without the startup options. – sotn Sep 26 '15 at 18:14
  • https://github.com/rails/rails/blob/v4.1.1/railties/lib/rails/commands/server.rb#L17 according to this in v4.1.1 default host is `0.0.0.0`. Are you sure Rails is 4.1.1? – dimakura Sep 26 '15 at 18:19