# Serving a static page alongside Ghost

- Link: https://tongfamily.com/2015/02/18/serving-a-static-page-alongside-ghost/
- Published: 2015-02-18T19:33:03-08:00
- Author: rich

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](http://nginx.com/resources/admin-guide/serving-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](http://www.nginxtips.com/nginx-location-directive/)
which is actually pretty tricky and hard to read so some examples because this is
basically a funky regular expression locator (see [documentation](http://nginx.org/en/docs/http/ngx_http_core_module.html#location)).
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://richtong.net/ 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://
richtong.net/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://richtong.net/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$ { } `

### Share this:

 * [  Mastodon ](https://tongfamily.com/2015/02/18/serving-a-static-page-alongside-ghost/?share=mastodon)
 * [  LinkedIn ](https://tongfamily.com/2015/02/18/serving-a-static-page-alongside-ghost/?share=linkedin)
 * [  Facebook ](https://tongfamily.com/2015/02/18/serving-a-static-page-alongside-ghost/?share=facebook)
 * [  WhatsApp ](https://tongfamily.com/2015/02/18/serving-a-static-page-alongside-ghost/?share=jetpack-whatsapp)
 * [  Email ](https://tongfamily.com/2015/02/18/serving-a-static-page-alongside-ghost/?subject=%5BShared%20Post%5D%20Serving%20a%20static%20page%20alongside%20Ghost&body=https%3A%2F%2Ftongfamily.com%2F2015%2F02%2F18%2Fserving-a-static-page-alongside-ghost%2F&share=email)
 * [More](https://tongfamily.com/2015/02/18/serving-a-static-page-alongside-ghost/#)

 * [  Telegram ](https://tongfamily.com/2015/02/18/serving-a-static-page-alongside-ghost/?share=telegram)
 * [  Print ](https://tongfamily.com/2015/02/18/serving-a-static-page-alongside-ghost/#print?share=print)
 * [  Pinterest ](https://tongfamily.com/2015/02/18/serving-a-static-page-alongside-ghost/?share=pinterest)
 * [  Tumblr ](https://tongfamily.com/2015/02/18/serving-a-static-page-alongside-ghost/?share=tumblr)
 * [  X ](https://tongfamily.com/2015/02/18/serving-a-static-page-alongside-ghost/?share=twitter)

### Like this:

Like Loading…
