21 C
Texas

Multiple Ghost Instances on a Single Server

Hosting different domains on different nodes cost you more and that’s what Virtual Hosting add more benefit by allowing multiple domains to co-exists within a single server. However, the same concept to get working on Ghost there some additional steps that required. Let jump and get started.

Core areas that we will be working on:

  • Make a copy of the existing Ghost instance and tweak some setting to host new blog
  • Add additional VirtualHost on nginx to host the new domain – newblog.osradar.com
  • Manage separate DB within MySQL to host the new blog
  • Create systemD unit files to manage each blog

 

Getting Started

Note that through out the document, I will stick to Ubuntu 18.04 OS version.

Step 01 — Copy the existing Ghost instance and make the necessary changes

- Advertisement -
# cd /var/www/
# cp -pr ghost ghost-new
# cd /var/www/ghost-new/system/files/
# mv blog.osradar.com.conf newblog.osradar.com.conf

Step 02 — Create new VirtualHost

# cd /etc/nginx/sites-available/
# ln -s /var/www/ghost-new/system/files/newblog.osradar.com.conf newblog.osradar.com.conf
# cd /etc/nginx/sites-enabled/
# ln -s /etc/nginx/sites-available/newblog.osradar.com.conf newblog.osradar.com.conf
# vim /etc/nginx/sites-enabled/newblog.osradar.com.conf
server {
    listen 80;
    listen [::]:80;

    server_name newblog.osradar.com;
    root /var/www/ghost-new/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:2369;
        
    }

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

    client_max_body_size 50m;
}

 

Step 03 — Manage new MySQL DB

# mysql -uroot -p
mysql> create database new_blog_osradar;
mysql> GRANT ALL ON new_blog_osradar.* TO root@'localhost'
mysql> flush privileges;

new_blog_osradar => is a new database to host the new blog

# grep database /var/www/ghost/config.production.json

  "database": {
      "database": "ghost_production"

ghost_production => is the database name for the existing Ghost instance. Lets back it up and restore with the newly created DB.

# mysqldump -uroot -p --no-data ghost_production > backup.sql
# mysql -uroot -p new_blog_osradar<backup.sql

Lets change the  required configuration in the new instance of Ghost

# vim /var/www/ghost-new/config.production.json
{
  "url": "http://newblog.osradar.com",
  "server": {
    "port": 2369,
    "host": "127.0.0.1"
  },
  "database": {
    "client": "mysql",
    "connection": {
      "host": "localhost",
      "user": "root",
      "password": "password",
      "database": "new_blog_osradar"
    }
  },

 

Step 04 — Create new SystemD unit file

# cd /etc/systemd/system/
# cp ghost_blog-osradar-com.service ghost_newblog-osradar-com.service
# vim ghost_newblog-osradar-com.service
[Unit]
Description=Ghost systemd service for blog: newblog-osradar-com
Documentation=https://docs.ghost.org

[Service]
Type=simple
WorkingDirectory=/var/www/ghost-new
User=999
Environment="NODE_ENV=production"
ExecStart=/usr/local/bin/node /usr/local/bin/ghost run
Restart=always

[Install]
WantedBy=multi-user.target

 

That’s it. Now its all about setting up DNS records from different domains to map the single IP address that we have on our system. So, when browse from http://blog.osradar.com to http://newblog.osradar.com Nginx will take care the routing in between domains.

“I hope this has been informative for you”

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article