[英]Rails Webrick server default IP and port
Rails -v 4.1.1 Ruby -v 2.2.1
我在一個AWS EC2實例上有2個Rails應用程序。 一個應用程序,我能夠使用以下命令在Webrick上啟動:
rails server
然后,我可以通過以下URL遠程訪問該應用程序:
http://[public_ip]:3000
第二個應用程序,我必須提供-b和-p選項。 如果沒有選項,則可以通過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.
適用於第二個應用程序的唯一服務器啟動選項是:
rails s -b 0.0.0.0 -p 3000
然后,我可以通過http://[public_ip]:3000
訪問第二個應用程序。 第二個應用程序是我在服務器上創建的全新應用程序。 第一個應用是我從現有應用中簽出的代碼。 如何使第二個應用程序的行為與第一個應用程序相同?
為Rails 4.2默認綁定主機之前rails s
命令是0.0.0.0
。 從Rails 4.2開始,它是localhost
。 因此,難怪您在新應用中遇到了這個問題。
如果您希望新應用程序自動從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
基於這個答案 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.