bluehallu
bluehallu

Reputation: 10295

Deploying Rails applications with Passenger and Nginx to VPS (EC2)

I've developed a couple of applications which I'm ready to deploy. To do so, I've configured Capistrano and I'm already able to run cap deploy, which runs properly. However, I'm totally lost as to how to continue from here. My setup is EC2 + Rails 3.2 + Ruby 1.9.3 + Passenger + Nginx (the one Passenger installs first time you try to start it) + Capistrano.

Until now, I just ran passenger start on my app root folder, which would start passenger on port 3000, and I would start the second app on port 3001. Now, what I need is to have this 2 apps under 2 different domains, say www.domain1.com and www.domain2.com.

  1. How am I supposed to start the servers now? I can go to the respective current folders that Capistrano created and run something like passenger start -e production -p 3001 -d and it starts running as a daemon, but, shouldn't capistrano take care of this? All I see is that, on each deploy, it touches the restart.txt file and that forces a "soft restart", which is not enough (as far as I know) if you've changed gems. Shouldn't Capistrano be starting and stopping Passenger, not me?

  2. How do I run the 2 apps on 2 domains? As far as I know, you can't point a domain to a port, and all I've managed to do now is to run 1 of the applications by running Passenger on port 80 with rvmsudo, but of course this only works for 1 application. After searching a bit I've found something about Nginx Virtual Servers. How do you do this? I mean, I have never touched anything specific to Nginx, just Passenger! Am I supposed to forget about Passenger and deal with Nginx as a service? How?

Thanks in advance!

Upvotes: 1

Views: 485

Answers (1)

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42909

I believe to start servers there's a specific cap command to start servers, but i don't know much about capistrano, just played with it a little bit before.

As for the second part, this is where nginx takes part, nginx will handle forwarding each domain to the specific port, using proxy_pass, take a look at this example

server {
    server_name: example1.com;
    proxy_pass: http://127.0.0.1:3000;
}
server {
    server_name: example2.com;
    proxy_pass: http://127.0.0.1:3001;
}

Upvotes: 1

Related Questions