Hosting Octopress on Nginx

Comments

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

1
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.

1
2
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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

1
2
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.

Comments