Adding Static content to Ghost

Looking to add static content to your website? Well, look no further.

First off, why do you want to do this? Well, maybe you want to monetise your website and host ads. Maybe you want security researchers to know how to contact you if there is an issue with your website. Or maybe, you want ot host something like a brochure or other static content without too much fuss.

In this article, we'll be looking at the configuration for Nginx specifically. This is just the web server I currently use for serving my blog but there will be a similar process for getting it working with other web servers too, such as Apache.

So, you need a few pieces of information before you start:

The file you want to host. Where you are going to put it. How it is going to be referenced in the URLs.

In my case, I place my static content in /opt/ghost/content/. This allows me to put all the files in one place and then reference out from there.

For something like my security.txt file, I follow the guidelines from https://securitytxt.org/ in terms of creating the actual file. I then upload it to the above directory, ready for Ghost to host the actual file.

I have a general alias for all my static content on /static/, so I have modified the configuration of nginx to that in the following way:

location /static/ {
  alias /opt/ghost/content/public/static/;
}
    

This doesn't really sort out the individual locations that the security,txt file should be located at. To do this, a little rince and repeat to add in the locations of /.well-known/ and just off the root of the web server.

location /.well-known/security.txt {
  alias /opt/ghost/content/public/static/security.txt;
}
location /security.txt {
  alias /opt/ghost/content/public/static/security.txt;
}
location /static/ {
  alias /opt/ghost/content/public/static/;
}

Finally, my completed code block looks like this, with the addition of Google's ads.txt.

location /ads.txt {
  alias /opt/ghost/content/public/static/ads.txt;
}
location /.well-known/security.txt {
  alias /opt/ghost/content/public/static/security.txt;
}
location /security.txt {
  alias /opt/ghost/content/public/static/security.txt;
}
location /static/ {
  alias /opt/ghost/content/public/static/;
}
As an Amazon Associate I earn from qualifying purchases.

If you have found this post useful, please consider donating.