Running static blog with nginx

If you created your blog without php/ruby (e.g. with jekyll or middleman, you need a webserver to serve the page.

If you host it with nginx, this is a very basic template:

server {
    listen               *:80;
    server_name          example.org;

    gzip             on;
    gzip_min_length  1000;
    gzip_types       text/plain application/xml application/json text/css application/x-javascript;
    gzip_disable     "MSIE [1-6]\.";

    root   /home/example/live/_site/;

    index index.html;

This returns all stuff of the folder /home/example/live/_site. If the files are bigger then 1KB, they will be served with gzip.

To redirect all your www.example.org requests to example.org, you have to add another server:

server {
    listen               *:80;
    server_name www.example.org;
    rewrite ^(.*) http://example.org$1 permanent;

To avoid UA-Compatible in your meta head (because w3c validator complains), you might add a special header:

add_header X-UA-Compatible "IE=edge,chrome=1";

So far your sites are available as /folder/index.html and /folder/. That's why it's duplicate content for google and looks ugly.

This can be resolved with this snippet:

    expires       @15m;

    location ~ ^/.*index.html$ {
        if ($request_uri ~ index.html$)
            rewrite ^/(.*)index.html$ /$1 permanent;

        add_header    Pragma no-cache;
        expires       epoch;

This expires @15m; and expires epoch, does not cache .html files at all: but all other static image for 15 minutes. Adjust those times for your needs.

If you need your stuff served with ssl, you might look into the post HTTPS + NGINX with self signed SSL certificate.

In jekyll, linux, nginx, open source, ubuntu by @ 13 Dec 2013

comments powered by Disqus

Recent Files


Recent Dev-Articles

Read recently