Serving a static page alongside Ghost

0

I have almost forgotten how to use Ghost. It was a great experiment in building something with node.js on digital ocean and figuring nginx. Kind of proud it all actually works. Now its time to do some site validation and I need to be able to put a static page up there.
This is a little more complicated than wordpress on bluehost. You can’t just stick a page up there. Instead, you need to hack at the nginx configuration files to allow this. Basically, ghost is set to handle everything that. That is what the ‘/’ means and then the ~ means handle a specific page.
To get nginx to serve serve static content use the syntax, which means declare a virtual server and set the root to the file system location /www/data and if you see a tilde, then do a match for the regular expression. Here, it says that all *.mp3 and *.mp4 should be found at /www/media while locations like / and /images use the root defined above:

server {
    root /www/data;
    location / {
    }
    location /images/ {
    }
    location ~ \.(mp3|mp4) {
        root /www/media;
    }
}

As another example, this says that anytime you see /sitemap.xml, find this static file /var/www. This is useful for things like statics that you need at the top for things like verification. So if you want to do this

location ~ ^/(sitemap.xml) {
     root /var/www;
}

The key to understanding this is the Nginx Location Directive tutorial which is actually pretty tricky and hard to read so some examples because this is basically a funky regular expression locator (see documentation). Basically, Nginx searches through these looking for prefix strings to do matches, so it is looking for the start of things:
This matches only a search for root like https://www.tongfamily.com/ and says look for the current active root
location = / { }
This matches anything because all web requests being with a starting slash
location / { }
This matches are strings that start with img so anything that looks like https://www.tongfamily.com/img/
location /img/ { }
After doing this match, it then tries regular expressions which are denotes by a tilde
The caret tilde means means search and stop matching, so this looks for any string with a /img/ so all image assets live here
location ^~ /img/ { root /www/images/ }
The tilde means do case sensitive matching so this means look for things like https://tongfamily.com/data/
location ~ /data/ { }
It there is ~* it means case insensitive matching so this will match IMG or img or Img
location ~* /img/ { }
Finally you can use a complex regex to look for things like text files
location ~ \.txt$ { }

Related Posts

© All Right Reserved