[英]Rails Webrick server default IP and port
Rails -v 4.1.1 Ruby -v 2.2.1 Rails -v 4.1.1 Ruby -v 2.2.1
I have 2 rails applications on one AWS EC2 instance. 我在一个AWS EC2实例上有2个Rails应用程序。 One app, I am able to startup on Webrick with: 一个应用程序,我能够使用以下命令在Webrick上启动:
rails server
I am then able to access the application remotely at the following URL: 然后,我可以通过以下URL远程访问该应用程序:
http://[public_ip]:3000
The second app, I have to provide the -b and -p options. 第二个应用程序,我必须提供-b和-p选项。 Without the options accessing the application at http://[public_ip]:3000
gives me: 如果没有选项,则可以通过http://[public_ip]:3000
访问该应用程序,这给了我:
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
. 然后,我可以通过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
. 为Rails 4.2默认绑定主机之前rails s
命令是0.0.0.0
。 Starting from Rails 4.2 it's localhost
. 从Rails 4.2开始,它是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
: 如果您希望新应用程序自动从0.0.0.0
开始, config/boot.rb
包含在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 . 基于这个答案 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.