In Ghost blog, I tried to export this current blog - as json - and import it to the new blog.

However, I received the error:

Import failed
Request is larger than the maximum file size the server allows

Looking at the server's response it was:

413 Request Entity Too Large
nginx/1.17.3

So my nginx proxy refuses to process a file this big in the upload.

nginx.config per domain

With the nginx-proxy docker image, there's a way to create hostname specific configurations:

I have mapped the folder ./nginx/vhost.d to /etc/nginx/vhost.d inside the container.

In that folder I can create a file named after the hostname. In this case:

blog-test.aaronlenoir.com

Configure entity size

According to this website I must add a client_max_body_size setting to the ´http´, ´server´ or ´location´ context.

In my case, the config files are by default in the location context so I can add a line:

client_max_body_size 2M;

The file is about 1.6M so this should be enough.

Restart nginx

To restart I take down all the containers using docker-compose:

sudo docker-compose down

And I restart it back in "background mode" (-d):

sudo docker-compose up -d

If there are no errors with my config, the nginx docker container will be up and running quickly, otherwise it'll probably bail out and I will have to look at the docker-compose output.

Luckily, everything started up without a hitch!

Import Warnings

After this change, I was able to import all posts.

There were a few warnings:

  • User: Entry was imported, but we were not able to resolve the following user references: created_by, updated_by. The user does not exist, fallback to owner user.
  • User: Entry was not imported and ignored. Detected duplicated entry.
  • Settings: Theme not imported, please upload in Settings - Design
  • Settings: Permalink Setting was removed. Please configure permalinks in your routes.yaml.

Only the last one, I think, will require some looking into.

On my blog, I enable permalinks. This adds a date to the URL. Apparently, according to the warning, I should use routes.yaml for this.

In the "Labs" section of ghost I can upload a routes configuration file. But I'm not sure what I should put in the file.

The default, according to the Ghost 2 docs, looks like this:

routes:

collections:
  /:
    permalink: /{slug}/
    template: index

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

My current blog posts have a URL in the form of:

https://blog.aaronlenoir.com/<YYYY>/<MM>/<DD>/<POST_TITLE>

This post on Some Dude's Tech Blog already details how to do this.

The permalink line needs updating to /{year}/{month}/{day}/{slug}/:

routes:

collections:
  /:
    permalink: /{year}/{month}/{day}/{slug}/
    template: index

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

So I put this in a routes.yaml file and upload it ... this did the trick.

Checking on the server, the file is stored in: data/ghost/settings.

It may seem unimportant, but when I add a third party comment app to my blog, the comments from the old blog will still be there if the URL of the posts remains the same.

Images

The json that exports my posts does not include images.

For this, I must copy the "images" folder from my original blog to the new one. The images folder can be found in data/ghost/images

Since both are on the same server, I could do this in a single command:

cp -a ~/aaronlenoir.com/blog/data/ghost/images ~/aaronlenoir.com/blog2/data/ghost

Conclusion

In this post I wanted to import my existing posts in a blog running on Ghost 1.25.7 to a new blog running on Ghost 2.

I exported my posts using the Labs section in the Administration section.

That gave me a 1.6 MB JSON file which I could not upload because nginx limited the upload size. I changed the setting client_max_body_size to be 2M, which allowed me to import the posts.

Secondly, I made sure the URL's to the posts remained the same by restoring the "permalink" setting that includes the date in my posts.

Finally, I copied over all images from my old posts, which were not included in the export.

I had some other warnings during the import. They were not so important: couldn't find an old author and a duplicated entry. Finally, it complained it could not find my custom theme. But that's for next time.