/ Installation

How To Install Multiple Ghost on One Server

If you are developer like me, install multiple ghost on one server will save your cost to rent a server.

I assume you already know how to install ghost at DigitalOcean.

There are two scenarios to do this:

  1. Using domain name
  2. Using ip address

PS: You need to use subdomain http://sub.yourdomain.com rather than subfolder http://yourdomain.com/sub


We already have nginx server and MySQL. We only need another ghost in different directory. So, we will create another directory and install ghost in it.


Using domain name

First, you need to create DNS record for your domain
dns-record-ghost


  1. Create a new folder inside /var/www
sudo mkdir -p /var/www/anotherghost

sudo chown [user]:[user] /var/www/anotherghost

sudo chmod 775 /var/www/anotherghost
  1. Install Ghost inside /var/www/anotherghost
ghost install

Now when you are prompted a question Enter your blog Url, insert your http://anotherghost.yourdomain.com

The rest question is same like here. Now, you have been installed another ghost on one server.


Using ip address

Create another ghost directory and install ghost like above.

Now when you are prompted a question Enter your blog Url, insert your http://youripaddress/anotherghost

Now, you need to edit your nginx server.

Go to /etc/nginx/sites-available you will see file with youripaddress.conf.

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

    server_name 192.168.0.1;
    root /var/www/ghost/system/nginx-root;

    location / {
        root /var/www/ghost/system/nginx-root;
        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:2368;
    }

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

    client_max_body_size 50m;
}

You need to add new location like this:

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

    server_name 192.168.0.1;
#   root /var/www/ghost/system/nginx-root;

    location / {
        root /var/www/ghost/system/nginx-root;
        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:2368;
    }

    location /anotherghost {
        root /var/www/blog/system/nginx-root;
        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:2369;
    }

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

    client_max_body_size 50m;
}

2369 is port that used by Ghost. Every time we install Ghost, the port number will be increased by auto. Ghost port start from 2368.

We can see which port that is being used from /var/www/yourdirectory, then we will find config.production.json

{
  "url": "http://192.168.0.1/anotherghost",
  "server": {
    "port": 2369,
    "host": "127.0.0.1"
  },
  "database": {
    "client": "mysql",
    "connection": {
      "host": "localhost",
      "user": "ghost-280",
      "password": "tXEz(N)q!)d1hD8uqR0a",
      "database": "blog_prod"
    }
  },
  "mail": {
    "transport": "Direct"
  },
  "logging": {
    "transports": [
      "file",
      "stdout"
    ]
  },
  "process": "systemd",
  "paths": {
    "contentPath": "/var/www/blog/content"
  }
}

Summary

  1. We can add multiple Ghost at one server.
  2. Using domain name is easier rather than using ip address. We dont need to edit nginx server.