简体   繁体   English

Ruby on Rails。 如何在Amazon Ec2上同时运行两个服务器(不同的应用程序)?

[英]Ruby on Rails. How to run two servers (different apps) on Amazon Ec2 at same time?

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: 我正要在一个Ec2中部署两个不同的Rails应用程序,我可以每次运行一个并且可以正常工作,但是我需要同时运行两个应用程序,并且可以从任何地方访问它,不仅本地主机,我启用(添加规则)两个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. 还尝试使用-b0.0.0.0运行app1,以便它可以从任何地方侦听,但结果相同:只有1个应用在侦听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. 如何同时运行两台服务器并在0.0.0.0上侦听两者。 thanks 谢谢

By default, according to the Rails documentation , the server will only listen on the localhost / loopback interface. 默认情况下,根据Rails文档 ,服务器将仅在localhost / loopback接口上侦听。 This is actually confirmed in the output snippet that you posted. 这实际上是在您发布的输出代码段中确认的。

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. 两个应用程序都可以侦听0.0.0.0 ,但是它们不能共享同一端口。 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. 您已经将app1配置为在端口3000上侦听(默认为“ Rails”),并且将app2为在端口3001上侦听,因此一旦进行上述更改,它们就应该和平共处。

See also: What does binding a Rails Server to 0.0.0.0 buy you? 另请参阅: 将Rails Server绑定到0.0.0.0有什么好处?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM