【问题标题】:bind rails app on the IP provided by the host with 3000 port在 3000 端口主机提供的 IP 上绑定 rails app
【发布时间】:2017-05-13 19:05:57
【问题描述】:

我正在我的主机提供的 VPS 服务器上运行 rails 应用程序。

我需要在他们提供的IP上运行同一个本地应用。

例如myip:3000

这样可以吗,主机提供的IP是公网/全局IP。

我该怎么做?抱歉这个愚蠢的问题。

【问题讨论】:

  • 您可以使用-b 选项在您的IP 地址上运行,例如rails s - b 111.222.333.444 -p 3000
  • 哦,是的,我忘记在命令中添加 -b 了。谢谢

标签: ruby-on-rails server port


【解决方案1】:

Rails 4.2 发布后,您无法从另一台计算机/虚拟机访问开发模式 rails 服务器(远程访问)。所以你需要将服务器绑定到ip。你可以这样做:

rails s -b 0.0.0.0

0.0.0.0(表示监听所有接口)

如果你想永久地这样做,你可以通过修改 config/boot.rb 来做到这一点:

require 'rubygems'  

需要'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

来源: https://fullstacknotes.com/make-rails-4-2-listen-to-all-interface/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-02
    • 1970-01-01
    • 2016-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    相关资源
    最近更新 更多