Hosting Octopress on nginx

octopress, nginx
This post is too old to be of any use. It has been archived.

The best thing about Octopress is that it makes it easier to switch to one of the servers out there which are faster than Apache - Nginx, lighttpd, or services such as Amazon S3. I went for nginx.

Deploying Octopress to my server

For now I want to self-host my site on my Linode. Since both my server and my local machines are fresh installs, I first needed to set up users, SSH keys and suchlike.

With that done, I toyed with the idea of deploying Octopress via Dropbox - I mean, could it get any easier? Just symlink the public folder into dropbox

ln -s /path/to/octopress/Public /Users/ME/Dropbox/gotofritz.net

and then install Dropbox on the server and do the same on that side. But somehow I felt reluctant to do that.

Instead I picked rsync as the deploy method.

Deploying Octopress with rsync

It's really as simple as the instructions on the Octopress site say - you change a couple of settings in the Rakefile, and then you run rake deploy.

Hosting Octopress on nginx

Installing nginx on Ubuntu

I didn't have nginx on my server, so I installed it and started it a version which includes naxsi, an nginx firewall.

apt-get install nginx-naxsi
/etc/init.d/nginx start

I then changed some of the settings in /etc/nginx/nginx.conf - enabled gizipping, added the location of the log files, nothing too weird.

Then I created a config file in /etc/nginx/sites-available/gotofritz.net

server {
    listen       80;
    server_name  www.gotofritz.net;
    return       301 http://gotofritz.net$request_uri;
}

server {
    listen       80;
    server_name  blog.gotofritz.net;
    return       301 http://gotofritz.net/blog$request_uri;
}

server {
    listen       80;
    server_name  work.gotofritz.net;
    return       301 http://gotofritz.net/work$request_uri;
}

server {
    listen       80;

    root ...
    index index.html;

    server_name gotofritz.net;
    access_log ...
    error_log ...


    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/www;
    }


    # do not serve pages starting with .
    location ~ /\. {
        log_not_found off;
        deny all;
    }

    ### This location definition prevents Nginx from serving any files which begin
    ### with a dollar sign, so Nginx will refuse to serve out a temp file if you
    ### are doing any editing inside a web-available directory
    location ~ ~$ {
        access_log off;
        log_not_found off;
        deny all;
    }

    ### These next two locations simply prevent Nginx from logging every time the
    ### favicon & robots.txt files are accessed, to keep the logs clean
    location = /robots.txt {
    access_log off;
    log_not_found off;
    }

    #don't need these for static site
    location ~ \.(aspx|php|jsp|cgi)$ {
            return 410;
            access_log off;
    }

    location = /favicon.ico {
    access_log off;
    log_not_found off;
    }

    location ~ \.js {
    access_log off;
    log_not_found off;
    }

    location ~ \.css {
    access_log off;
    log_not_found off;
    }

}

Created a symlink between sites-available and sites-enabled, then restarted the server

ln -s ../sites-enabled/gotofritz.net gotofritz.net
sudo /etc/init.d/nginx restart

Anf off we go. Check out the speed - it's actually faster to load the page from my Linode in the UK than it is to load it locally on my machine using Pow.