新建的rails4.2.6项目,项目不能通过内网ip:3000访问,只能localhost:3000访问。
由于Rails4.2之前都是默认绑定到 0.0.0.0,Rails 4.2 就默认绑定 localhost 了。
默认启动后控制台信息如下:
Rails 4.2.2 application starting in development on http://localhost:3000
通过IP访问要做如下修改:
进入项目下的config/boot.rb目录修改如下
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' # Set up gems listed in the Gemfile.
require 'rubygems'
require 'rails/commands/server'
module Rails
class Server
alias :default_options_bk :default_options
def default_options
default_options_bk.merge!(Host: '0.0.0.0')
end
end
end
启动后控制台信息如下:
Rails 4.2.2 application starting in development on http://0.0.0.0:3000