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?
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.