简体   繁体   中英

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:

/path/app1$ rails s -d 

/path/app2$ rails s -b0.0.0.0 -p 3001 -d

this is the ps -ef command output

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

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.

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:

/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.

See also: What does binding a Rails Server to 0.0.0.0 buy you?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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