I am triyn to deploy two different rails app in one Ec2 i can run one each time and work ok, but i need the 2 app running at same time and that can be accessed from anywhere not only localhost,I enable (add rule) two tcp port 3000 and 3001, this is my try:
我是triyn在一个Ec2中部署两个不同的rails应用程序我可以每次运行一个并且正常工作,但我需要同时运行的2个应用程序,并且可以从任何地方访问,不仅是localhost,我启用(添加规则)两个tcp端口3000和3001,这是我的尝试:
/path/app1$ rails s -d
/path/app2$ rails s -b0.0.0.0 -p 3001 -d
this is the ps -ef command output
这是ps -ef命令输出
dev+ 3028 1 0 17:10 ? 00:00:00 puma 3.11.2 (tcp://localhost:3000) [/]
dev+ 3160 1 0 17:14 ? 00:00:00 puma 3.11.3 (tcp://0.0.0.0:3001) [/]
also try to run app1 with -b0.0.0.0 so it can listen from anywhere, but same result: only 1 app is listening on 0.0.0.0. What I am missing? How can I run two servers at same time and listen both on 0.0.0.0. thanks
还尝试使用-b0.0.0.0运行app1,这样它可以从任何地方收听,但结果相同:只有1个应用正在监听0.0.0.0。我错过了什么?如何同时运行两台服务器并在0.0.0.0上同时监听。谢谢
1 个解决方案
#1
1
By default, according to the Rails documentation, the server will only listen on the localhost / loopback interface. This is actually confirmed in the output snippet that you posted.
默认情况下,根据Rails文档,服务器将仅侦听localhost / loopback接口。这实际上已在您发布的输出代码段中得到确认。
In the first command for app1
, you aren't telling it to listen on 0.0.0.0
, so you'd need to change your first command to:
在app1的第一个命令中,你没有告诉它监听0.0.0.0,所以你需要将你的第一个命令改为:
/path/app1$ rails s -b0.0.0.0 -p 3000 -d
Both applications can listen on 0.0.0.0
, but they can't share the same port. You have already configured app1
to listen on port 3000 (Rails default), and app2
to listen on port 3001, so they should both coexist peacefully, once you make the change above.
两个应用程序都可以侦听0.0.0.0,但它们不能共享同一个端口。您已经将app1配置为侦听端口3000(默认为Rails),并将app2配置为侦听端口3001,因此一旦您进行了上述更改,它们应该和平共存。
See also: What does binding a Rails Server to 0.0.0.0 buy you?
另请参阅:将Rails服务器绑定到0.0.0.0的内容是什么?
#1
1
By default, according to the Rails documentation, the server will only listen on the localhost / loopback interface. This is actually confirmed in the output snippet that you posted.
默认情况下,根据Rails文档,服务器将仅侦听localhost / loopback接口。这实际上已在您发布的输出代码段中得到确认。
In the first command for app1
, you aren't telling it to listen on 0.0.0.0
, so you'd need to change your first command to:
在app1的第一个命令中,你没有告诉它监听0.0.0.0,所以你需要将你的第一个命令改为:
/path/app1$ rails s -b0.0.0.0 -p 3000 -d
Both applications can listen on 0.0.0.0
, but they can't share the same port. You have already configured app1
to listen on port 3000 (Rails default), and app2
to listen on port 3001, so they should both coexist peacefully, once you make the change above.
两个应用程序都可以侦听0.0.0.0,但它们不能共享同一个端口。您已经将app1配置为侦听端口3000(默认为Rails),并将app2配置为侦听端口3001,因此一旦您进行了上述更改,它们应该和平共存。
See also: What does binding a Rails Server to 0.0.0.0 buy you?
另请参阅:将Rails服务器绑定到0.0.0.0的内容是什么?