Multiple Rails Apps On One Digital Ocean Droplet

How to have multiple rails app on one digital ocean droplet

  1. Create a new nginx server block on your droplet with the name of your app
sudo nano /etc/nginx/sites-enabled/NAMEOFYOURAPPHERE
  1. Add the nginx server code
server {
  listen 80;
  listen [::]:80;

  server_name WEBSITEURL www.WEBSITEURL;
  root /home/deploy/APPNAME/current/public;

  passenger_enabled on;
  passenger_app_env production;

  location /cable {
    passenger_app_group_name APPNAME_websocket;
    passenger_force_max_concurrent_requests_per_process 0;

  # Allow uploads up to 100MB in size
  client_max_body_size 100m;

  location ~ ^/(assets|packs) {
    expires max;
    gzip_static on;
  1. Create the production database for your app

3.1 change your user: sudo su - postgres 3.2 create the db: createdb -O db-deploy APP_DB_NAME

  1. Add capistrano to your rails app Gemfile
gem 'capistrano', '~> 3.11'
gem 'capistrano-rails', '~> 1.4'
gem 'capistrano-passenger', '~> 0.2.0'
gem 'capistrano-rbenv', '~> 2.1', '>= 2.1.4'

4.1 Run bundle install

4.2 Run cap install STAGES=production

4.3 Add lines to Capfile:

require 'capistrano/rails'
require 'capistrano/passenger'
require 'capistrano/rbenv'

set :rbenv_type, :user
set :rbenv_ruby, '2.6.3'

4.4 Modify config/deploy with app git repo details:

set :application, "myapp"
set :repo_url, ""

# Deploy to the user's home directory
set :deploy_to, "/home/deploy/#{fetch :application}"

append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', '.bundle', 'public/system', 'public/uploads'

# Only keep the last 5 releases to save disk space
set :keep_releases, 5

4.5 Modify config/deploy/production.rb with your server id

server '', user: 'deploy', roles: %w{app db web}

  1. Go into the server to add environment variables
     ssh deploy@
     mkdir /home/deploy/myapp
     nano /home/deploy/myapp/.rbenv-vars

5.1 Add your secret key base and database url (check other apps for reference

# For Postgres

# For MySQL


# etc...

Join my newsletter

If you want to receive my latest essays and interesting finds subscribe to my list: