Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I host multiple Rails apps with nginx and Unicorn?

How can I host multiple Rails apps with nginx and Unicorn?

I currently have one site up and running thanks to "Deploying to a VPS".

I have searched but I need a step-by-step guide to get this working. The results I found are not so well explained to help me understand how to accomplish this.

like image 422
Timmie Sarjanen Avatar asked Oct 10 '12 21:10

Timmie Sarjanen


1 Answers

Basically, you do the same thing you did to get everything for your first application running minus the Nginx installation. So, however you got your Unicorn instance for your first application running, do it again for your next application.

You can then just add another server block into your Nginx config with an upstream that points to that new Unicorn instance.

One Nginx running for the entire machine will do fine, with one Unicorn running per application.

Hope this helps some.


Here is a sample of the additional server block you would need to add for Nginx to serve additional applications:

upstream unicorn_app_x {
  server unix:/path/to/unicorn/socket/or/http/url/here/unicorn.sock;
}

server {
  listen 127.0.0.1:80;
  server_name mysitehere.com aliasfor.mysitehere.com;
  root /path/to/rails/app/public;

    location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    if (!-f $request_filename) {
      proxy_pass http://unicorn_app_x;
      break;
    }
  }
}
like image 76
SoapiestWaffles Avatar answered Oct 29 '22 22:10

SoapiestWaffles