Albrechts Blog

About programming, mostly.

How My Other Site Was Built

When planning my other blogging site I have had some ideas what I want to achieve. I wanted a typical blog site but with extra flexibility for trying out other stuff and learning about different tools I am interested in.

I have had a special setup in mind: hosted on my own web server, no dynamic / interpreted content on the server side, just static pages. For sure the pages need to be generated by a flexible enough mini CMS.

So instead of going on with blogger.com I wanted to control my own web server and build it from ground up. But I also had a very limiting requirement: no cost. Yes, I want to try out stuff without paying anything more for it.

So the first thing to decide was about the web server. Luckily, Amazon currently offers a year of free testing their hosting services. I setup a server on AWS with the latest Debian and read about the service details that are included in Amazons free offer. Two things to keep in mind: First, you have absolutely no guarantee on backups being made nor failsafety etc. So it is vital to have your setup elsewhere in case your server is being reset to factory defaults. I chose to prepare everything on my laptop and rsync stuff in case of changes. More on that later. Second, you have one fix IP address (they call it Elastic IP) to be bound on your instances. In case you would like to have a meaningful web server name using a dynamic DNS hoster, you can register the Elastic IP there and give it a go. But a more flexible approach is to register your IP automatically when your interface is up using a script in /etc/network/if-up.d like so: $$code(lang=bash, style=monokai)

PubIP=$(curl http://169.254.169.254/latest/meta-data/public-ipv4)
curl --user ${USER}:${PASSWD} https://www.dnsdynamic.org/api/?hostname=${HOST}&myip=${PubIP}

$$/code Note: This works if you define USER, PASSWD and HOST before.

The result of this setup was an always-on server reachable in the internet using a meaningful name. Next step was to decide which http server to use. I wanted a minimalistic setup, but after reading a while here and there I learned that there are no good alternatives to Apache or Nginx. Since I am experienced with Apache I went with Nginx to learn something new. Well, Nginx seems to be a bit easier to setup, but in the end it is just working like Apache.

OK, server is running, what about the CMS? After researching a while I went with Blogofile which calls itself a “static website compiler”. That was exactly what I was looking for and I installed it on my laptop.

Blogofile gives you for each site a basic setup including features like Blogs etc. It is Python based (but it can be used without Python knowledge). It uses Mako Templates as a template engine which makes it easy to change layout and reorganize stuff. For blog posts it supports markdown which I find handy to use.

As a result, whenever I would like to add a blog post I have to add a markdown file in the posts directory and redeploy the site. For redeployment I am using the following script: $$code(lang=bash, style=monokai)

blogofile build -s ${site}
rsync -avz -e ssh ${site}/_site/ ${sshhost}:/var/www/

$$/code Works like a charm.

If ever the AWS server dies, I would have to reinstall and configure Nginx and the dyndns script, done. If ever my laptop dies, I would be screwed. Setting up programs like Blogofile is no fun but possible, but the valuable content would be lost. Therefore I commit my stuff to Github.

For me, this is a fun project. I have learned about EC2 on amazon, setting up and securing Debian, writing shell scripts, Nginx, Blogofile, a little bit Python, and Git on Github. And it gives enough room to play around.

Comments