Ask A Question

Notifications

You’re not receiving notifications from this thread.

Deploy Multiple Rails Apps to Same DigitalOcean Droplet?

Michael Stitt asked in General

I've used your guide to deploy a Rails app to a DO droplet -- which was extremely helpful! However, now I'm at the point where I'd like to take advantage of this existing droplet and deploy other Rails apps that I'm working on (mostly just landing pages at the moment).

Do you have any advice on how to go about this or can you point to any documentation implementing this? Are there any things I need to think about when sharing a VPS with multiple Rails apps?

Thanks!

Reply

You'll love this, it's almost too simple.

For your new app, you can basically copy the Capistrano configs from the old one and change the app name in all the places. You'll need to add another server block to your Nginx config, restart Nginx, and create a new database for this app. That's it. Just deploy like you did before, and create the database.yml file on the server to point to the new database and you're off to the races.

Changing the domain name in the nginx config and pointing a second domain to the same server is all you need to do in order to have Nginx serve up two sites from the same machine.

You can basically just follow those same steps from the guide, but skip the installation parts and go straight to the nginx config, database, and capistrano pieces.

Reply

Sweet! I'll do that later today and let you know if I run into any hiccups.

Thanks again for producing great content on such a consistent basis!

Reply

You got it! :) I appreciate that a lot. I've been trying to make sure it all stays up-to-date as much as possible.

Lemme know if you hit any snags!

Reply

Hi, I am getting the same issue, i followed your server setup tutorial and it works fine. but now i want to deploy another rails application on same server, i dont know how to configure my next application. My default file (/etc/nginx/sites-enabled/default) settings are given.

Default settings

server {

    listen 80;
    listen [::]:80 ipv6only=on;
            server_name mydomain.com;
    passenger_enabled on;
    rails_env    production;
    root         /home/ubuntu/projects/blog/public;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

}
Please guide me how to configure more apps. If you can show me the code example it'll be more helpful.
Thanks in advance.

Reply

That issue was resolved

Reply

That issue was resolved

Reply

That issue was resolved

Reply

That issue was resolved

Reply

That issue was resolved

Reply

Hey Muneeb,

Just create a new file in the /etc/nginx/sites-enabled directory. Name it whatever you want, just not default since that's already being used.

Reply

Hi Chris,

Thank you so much for your reply. I did the same thing. I created a new file in sites-enabled same name as my project and paste the configurations as
server {

listen 80;
listen [::]:80 ipv6only=on;
        server_name mydomain.com;
passenger_enabled on;
rails_env    production;
root         /home/ubuntu/projects/site2/public;
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   html;
}

}

But it is giving me an error that port 80 is already used. but when i changed port form 80 to 8080 this is not accessable from browser. i am using ubuntu 16.4.

Reply

Hey Muneeb,

Check out this post and the comment on solutions for that. https://stackoverflow.com/a/15101745/277994

Reply
Try Chris's hatchbox.io
I have seen the "How it Works Video" and I am very impressed. I am not a dev op guy and not very comfortable with Capistrano and Chef. I have multiple Rails Apps to manage and I think Hatch will do a lot of "dev op" work for me leaving me with time to focus on shipping products (I do an app every couple of months or so and a major app every 6 months to a year."
I am hoping Chris offers his GoRails subscribers a discount coupon ;)
Regards
Vikram
Reply

Hi @Chris
I was not aware of your articel and deployed rails app following
Deploying a Rails App on Ubuntu 14.04 with Capistrano, Nginx, and Puma

My first app is working fine
for second I added nginx.cong as

upstream puma {
  server unix:///home/myappuser/apps/ezlarm-server/shared/tmp/sockets/ezlarm-server-puma.sock;
}

server {
  listen 80 default_server deferred;
  listen [::]:80 ipv6only=on default_server deferred;
  # server_name example.com;

  root /home/myappuser/apps/ezlarm-server/current/public;
  access_log /home/myappuser/apps/ezlarm-server/current/log/nginx.access.log;
  error_log /home/myappuser/apps/ezlarm-server/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}

now when I restart nginx, it gives error

Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.

and systemctl status nginx.service shows this

nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2019-03-23 17:02:33 UTC; 1min 5s ago
     Docs: man:nginx(8)
  Process: 28592 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 28505 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 28594 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
 Main PID: 28509 (code=exited, status=0/SUCCESS)

not sure if this is right place to ask but can you point me towards right direction

Reply

Hey Muhammad, I think you'll need to take a look at /var/log/nging/error.log and see why it's failing. You can also run nginx -t to determine if you have a valid config. It might just be that you have a typo in your config somewhere.

Reply

Is there an updated version of this?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.