I recently moved my Ghost blog from levibostian.com to levibostian.com/blog.
I plan to create some sort of landing page for myself to expand my website instead of just making it a blog.
Here is how I did so:
- Open your
config.jsfile and edit your production URL to the subdirectory you want:
- Edit your NGINX config file to host your Ghost blog to your new directory:
Notice that I added a redirect in the new config file. This is not required for you. I decided to add the redirect simply because my home page is blank right now and might as well direct everyone to my blog in the mean time.
- Reboot server and you are pretty much done! Except for 1 problem. All of your images are now broken. All of your existing blog entry images are point to
/content/images/2016/93/whatever.pngwhen it needs to be pointing to
/blog/content/images/2016/93/whatever.png. When you upload an image inside of Ghost, it puts the link to all of your images hard coded into your post HTML in the database.
Therefore, you need to run a little SQL on your ghost blog database.
I host my blog on DigitalOcean. So, I connected to my blog via Filezilla and copied over:
<path to your ghost blog>/content/data/ghost.db to my local computer. From here I made a copy of this file and put it in my Dropbox for safe keeping just in case I screw up my SQL and need a backup! Then on another copy of this
ghost.db file, I went to work and executed some SQL on it.
No matter what OS you are running on your machine, you can find a SQLite tool. I run a Mac and use the tool DB browser. Using this tool, open up your database file and click on the tab "Execute SQL":
Copy/paste the following SQL code and hit the blue play button above the text box.
WARNING: I recommend you run this SQL with some knowledge of SQLite queries. I am not responsible for data loss of your database or screwing it up. This SQL below has been tested and works as of the time of this writing. Ghost may have changed the format since and this will not work anymore
update posts set image = replace(image, '/content/images/', '/blog/content/images/') where image like '/content/images/%'; update posts set markdown = replace(markdown, '/content/images/', '/blog/content/images/') where markdown like '%/content/images/%'; update posts set html = replace(html, '/content/images/', '/blog/content/images/') where html like '%/content/images/%'; update users set image = replace(image, '/content/images/', '/blog/content/images/') where image like '/content/images/%'; update users set cover = replace(cover, '/content/images/', '/blog/content/images/') where cover like '/content/images/%'; update settings set value = replace(value, '/content/images/', '/blog/content/images/') where value like '/content/images/%';
Simply, this is SQLite replace queries that go through the
markdown, html and image columns of the
posts table and replaces all
Save the DB after running the SQL query and copy back over your file via Filezilla.
After this is complete, you are done! Ghost should now work in your new location!