Let nginx serve static files for your ghost blog
You have probably heard about the blogging platform Ghost. The product is still in its infancy, having reached version 0.4.0 this month. But it's fun to try something so different from the standard Wordpress installation. Just don't expect a feature-complete stable product at this stage.
If you want to try Ghost on your own machine, just download the latest Ghost distribution, and follow the online installation instructions.
After installing Ghost you may want to fine-tune your setup. If you're using nginx as reverse proxy in front of ghost, you should consider making nginx serve all the static files (like images, css, and javascript). Because, this is one thing nginx is really good at, serving static files fast and efficient.
Below is a nginx configuration file, which illustrates how you can setup nginx to:
-
Reverse proxy to the ghost node.js process (note that I'm serving the blog from the
/blog
subdirectory, not from the root of the domain). -
Serve static content from
/content/images
,/assets
and/shared
, and thefavicon.ico
file. The/assets
directory contains files for your chosen theme, this configuration is for the default theme casper.
The ghost specific part of the nginx server config file:
# reverse proxy requests to ghost
location /blog {
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://localhost:2368;
proxy_pass_header X-CSRF-Token;
client_max_body_size 10M;
}
# serve the static blog assets
rewrite ^/blog(/content/images/.*) $1 break;
location /content/images {
internal;
root /home/ghost/ghost;
expires 1h;
}
rewrite ^/blog(/assets.*) $1 break;
location /assets {
internal;
root /home/ghost/ghost/content/themes/casper;
expires 1h;
}
rewrite ^/blog/(favicon.ico) /shared/$1 break;
rewrite ^/blog(/shared.*) $1 break;
location /shared {
internal;
root /home/ghost/ghost/core;
expires 1h;
}
If you keep an eye on your Ghost log file, you can see if there are even more static files that nginx can serve for you.