Static Files in Ghost with Rclone

Ghost is a powerful publication system, but currently doesn't support file hosting like Wordpress with their media library. Many ways to serve static files, but how to serve static files without connecting to server and manually upload files (via sftp/ftp)? use Rclone.

Static Files in Ghost with Rclone

Rclone ("rsync for cloud storage") is a command line program to sync files and directories to and from different cloud storage providers.

Rclone act as rsync but sync from cloud storage, in the local server using nginx to server web (combined with ghost).

Install Rclone

curl https://rclone.org/install.sh | sudo bash

Once installed, you need to configure rclone, each cloud service has different configuration, read yours here : https://rclone.org/docs/, choose your cloud service provider.

Set up NGINX and Root

Create static folder in ghost/ and then edit your domainname.tld.conf in folder ghost/system/files/, add those lines:

location /static/ {
  alias /var/www/ghost/static/;
  error_page 404 = @notfoundpage;
}

location @notfoundpage {
  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;
}

@notfoundpage is a handler for 404, that will redirect to 404 Page in Ghost Installation.

Set up continuously sync

Currently rclone sync doesn't provide realtime sync, we can use watch to run the command every X tim

watch -n X rclone sync name:cloud-folder /var/www/ghost/static/

Replace X with your interval time, name:cloud-folder with your remote name and remote folder.

Run this in screen or on your own service in background. That will look like this:

Try to upload file to your cloud service folder. Mine was https://fajar.co/static/rie.cfg