Reputation: 411
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.
Upvotes: 11
Views: 5337
Reputation: 1
The instructions provided above were not enough. my startup file: /etc/init.d/unicorn had several references to a single host's configuration. With these configurations, it would not serve a second host.
so I created a new startup instance of unicorn.
cp /etc/init.d/unicorn /etc/init.d/unicorn_app_x
edited /etc/init.d/unicorn_app_x, replacing references to the first site with references to the second: including the unique socket.
then I added the file to startup automatically: update-rc.d act_unicorn defaults
it finally worked!
Upvotes: 0
Reputation: 168
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;
}
}
}
Upvotes: 14