我的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)
答案 0 :(得分:2)
Rails检查pid文件是否已经存在。要运行单个应用程序的两个副本,您也应该更改pid:
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