dracoblue.net

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
@ 12 Dec 2013, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About