Migrating From Ghost 2.x to Jekyll, and Nginx Rewrite Rules

Background

I recently migrated my self-hosted instance of a Ghost Blog to Jekyll. Reasons being:

  • Ghost requires a database. Whether SQLite or MariaDB, I didn’t want to host and maintain that, or being restricted with scaling horizontally and syncing data.
  • I’m just hosting a small set of static content, and I want my CDN to more easily cache it without the extra hoops for javascript, which wouldn’t cache everything as I wanted it to.
  • I’m switching to hosting my stuff in the cloud on Kubernetes. And thus, I’ll be using the Nginx Ingress Controller to front everything and terminate TLS.

The earlier versions of Ghost had the prefix to the title of the post be a date (See my post on preserving that setup in later versions of Ghost), When using a converter (more on that in a second), the date prefix to my posts went from /2019/09/07/ to 2019-09-07-. My analytics tanked again (I wung it when I switched).

Post Migration

  • This ruby gem, jekyll_ghost_importer, was the simplest method of migrating posts (using a JSON export from the Ghost Admin Interface as its input).

Nginx Rewrite

  • I first tried using a more k8s-native method, with annotation nginx.ingress.kubernetes.io/rewrite-target, but I kept running into errors.
  • I let Nginx handle the redirect directly itself, through the annotation nginx.ingress.kubernetes.io/configuration-snippet:
    # redirect requests to url's the slashes in dates to dashes
    nginx.ingress.kubernetes.io/configuration-snippet: |
    if ($request_uri ~ "^\/\d{4}\/\d{2}\/\d{2}\/.+") {
      rewrite '^\/(?<year>\d{4})\/(?<month>\d{2})\/(?<day>\d{2})\/(?<remainder>.+)' /$year-$month-$day-$remainder redirect;
    }
    

    (change redirect to permanent for an HTTP permanent 301 instead of temporary 302 - but test it well first)

Now it redirects as I like: https://andrewaadland.me/2019/06/17/configuring-proxyprotocol-for-nginx-ingress-on-aws/ –> https://andrewaadland.me/2019-06-17-configuring-proxyprotocol-for-nginx-ingress-on-aws/. Google search results no longer return a 404.


© 2019. All rights reserved.

Powered by Hydejack v8.5.2