您的位置:首页 > 大数据 > 人工智能

rails 通过局域网ip连接访问本地Rails项目

2016-03-31 17:35 615 查看

新建的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[/code] 
通过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[/code] 
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: