Creating 2 ghost blogs on a single droplet

In this post you will learn :

  • How to configure 2 blogs running on the same droplet
  • How to configure a ghost blog on Digital Ocean

This blog now runs on Digital Ocean. In this post I will explain how I manage to configure 2 blogs running on the same droplet. Digital Ocean is a great alternative to AWS and it's pretty economical.
Here is a simple tutorial to get this going fast.

Steps:

  • Create a new droplet
  • Increase swap
  • Install Ghost (first blog)
    • Change the server port
  • Install Ghost (second blog)
    • Change the server port
  • Configure localhost
  • Configure cloudfare

Create a new droplet

This step is pretty self-explanatory. You can follow Digital Ocean guide on [this.] (https://www.digitalocean.com/community/tutorials/how-to-create-your-first-digitalocean-droplet)

Increase swap

Here's a quick simple tutorial to increase to 4G [1]

sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile


You can verify that the swap is properly install by :

sudo swapon --show

**Make it permanent: **

sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Install Ghost:

Following the instruction from the website, we have :
the website

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install nginx
sudo ufw allow 'Nginx Full'
sudo apt-get install mysql-server
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash 
sudo apt-get install -y nodejs
sudo npm i -g ghost-cli
sudo mkdir -p /var/www/ghost1
sudo mkdir -p /var/www/ghost2
sudo chown yann:yann /var/www/ghost1
sudo chown yann:yann /var/www/ghost2
cd /var/www/ghost1
ghost install

Here note that there are 2 installations of the Ghost blog. One in ghost1 and the other in ghost2.

Configure the newly built ghost server

There are 2 things you want to configure:

  • Localhost and port (so outside server can access it)
  • Nginx port

In file config.production.json, we have:

  "url": "http://www.mywebsite.com",
  "server": {
    "port": 2370,
    "host": "0.0.0.0"
  },

For Nginx configuration, based on your website name, you should update this file :
/etc/nginx/sites-enabled/www.learningiot.com.conf

server {
    listen 80;
    listen [::]:80;

    server_name www.learningiot.com;
    root /var/www/learningiot/system/nginx-root;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2370;

    }

    location ~ /.well-known {
        allow all;
    }

    client_max_body_size 50m;
}

make sure you edit the line proxy_pass http://127.0.0.1:2370; to the right port id.

Now restart ghost and Nginx:

 sudo service nginx restart
 ghost restart

Configure cloudfare:

This article will show you how to configure Cloudfare. I used the following method:

Using A and CNAME Entries

A          @          DROPLET_IP
CNAME      www        domain.com

References:


  1. Tutorial on how to add swap space on Ubuntu . ↩︎