Uploading and Serving files for Ghost Blogs
Coming from WordPress, I was surprised that Ghost only allowed images to be uploaded by default. I can recall many instances where blog owners want to upload PDFs, files, or mirror a file from another site.
Since we can't upload those sorts of files in Ghost, we'll be using WinSCP to upload and using nginx to serve those files.
Note: The following assumes you are running a standard installation of Ghost on your own server and have ssh access. I'm using Debian, instructions may vary for other systems.
Alright, let's begin. SSH into your server and navigate to your ghost installation folder and make a new folder called uploads.
drakeor@ghost-blog/var/www/ghost# ls
config.production.json content current system versions
drakeor@ghost-blog/var/www/ghost# mkdir uploads
drakeor@ghost-blog/var/www/ghost# ls
config.production.json content current system uploads versions```
Navigate to your nginx config folder and open your site's config. On my Debian system, it's /etc/nginx/sites-enabled/ghost.conf but yours may be different. We're going to scroll down down to the first location tag. Mine looks like this:
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:2368;
}
We're going to add a new location section to point to our new folder:
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:2368;
}
location /uploads/ {
alias /var/www/ghost/uploads/;
}
Now we just need to restart nginx.
drakeor@ghost-blog:~# service nginx restart
Last, we'll just need to upload a file to /var/www/ghost/uploads on WinSCP.
We'll see if it works by going to http://your-ghost-url/uploads/<filename>.
Here's my example file: https://drakeor.com/uploads/8080-Programmers-Manual.pdf
Congrats! You can now upload and serve files on your Ghost blog server!