ruby-on-rails - 具有绑定(bind)的多个并发 Rails 服务器

标签 ruby-on-rails windows binding lan

我的 LAN 有一个可用的 Rails 暂存服务器,如下所示:

rails server --binding=0.0.0.0 -p 3000

我现在想在我的 LAN 中打开第二个并发的 Rails 服务器,如下所示:

rails server --binding=0.0.0.0 -p 3001

不幸的是,我收到此错误消息:

...
=> Booting Puma
=> Rails 5.1.1 application starting in development on http://0.0.0.0:3001
=> Run `rails server -h` for more startup options
A server is already running. ...

仅当我在两台服务器上都使用 --binding=0.0.0.0 时才会出现此错误,如果我希望我的 LAN 可以访问它,这是必需的。

如何在同一台机器上向局域网开放多个 Rails 服务器,而不仅仅是 localhost

编辑:

尝试 Vasfed 的解决方案后,例如

rails server --binding=0.0.0.0 -p 3000 --pid=tmp/pids/server0.pid
rails server --binding=0.0.0.0 -p 3001 --pid=tmp/pids/server1.pid

问题仍然存在,但这次我有更多信息。这似乎与正在打开的端口 9292 有关...

=> Booting Puma
=> Rails 5.1.1 application starting in development on http://0.0.0.0:3001
=> Run `rails server -h` for more startup options
*** SIGUSR2 not implemented, signal based restart unavailable!
*** SIGUSR1 not implemented, signal based restart unavailable!
*** SIGHUP not implemented, signal based logs reopening unavailable!
Puma starting in single mode...
* Version 3.9.1 (ruby 2.4.1-p111), codename: Private Caller
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://0.0.0.0:9292
Exiting
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/puma-3.9.1/lib/puma/binder.rb:269:in `initialize': Only one usage of each socket address (protocol/network address/port) is normally permitted. - bind(2) for "0.0.0.0" port 9292 (Errno::EADDRINUSE)

最佳答案

Rails 检查 pid 文件是否已经存在。要运行单个应用程序的两个副本,您也应该更改 pids:

rails server --binding=0.0.0.0 -p 3000 --pid=tmp/pids/server1.pid
rails server --binding=0.0.0.0 -p 3001 --pid=tmp/pids/server2.pid

关于ruby-on-rails - 具有绑定(bind)的多个并发 Rails 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52820219/

相关文章:

windows-phone-7 - ListBox ItemsSource 绑定(bind)通过代码而不是通过 XAML

javascript - Ruby on Rails 动态引导模态表

javascript - 使用 Thumbs_up gem 在 Rails 4 中进行 AJAX 化投票

Javascript 和 Ruby on Rails

c - c mktime 在 Windows 和 GNU/Linux 上是否不同?

c++ - Gdiplus::Bitmap::FromHICON 失败

c# - 如何以编程方式查找 Windows 上的事件安全提供程序?

C# 问题 : How do I save changes made in a DataGridView back to the DataTable used?

c# - Xamarin 需要作为 commandParameter 从同一 xaml 的元素中选择项目

ruby-on-rails - 如何测试 301 重定向是否发生在 rspec 中?