Host Jekyll or any static site on Heroku for free

Written by
Date: 2012-07-07 22:25:00 00:00


With the costs of storage and bandwidth now a days, it is incredible easy to find a place to host your static site.

So, if you are using Jekyll, Hyde, nanoc, Pelican, or any similar tool to generate your site from textile or markdown documents, you can be sure you have a myriad of places to host your site.

Some of them are free, like GitHub page, Amazon S3 and Heroku, I'm going to show you how I have managed to host my Jekyll powered site (this site) on Heroku. Note: I may have moved it from Heroku by the time you are reading this.

Well, enough introduction. Time to work. The instructions below are focused on hosting Jekyll on Heroku but they are the same for any static site or content you would like to put on Heroku.

Prepare your system for heroku

I'm talking about Linux or Mac OS X

sudo gem install heroku
sudo gem install bundler

In my case, because I'm using Jekyll

sudo gem install jekyll

Prepare the folder from where you are going to deploy

mkdir -P ~/my_site/public

I only want to upload the site, and not the source of my blog so, I run Jekyll this way

jekyll ~/my-blog-source ~/my_site/public

Now, prepare the folder for the first deploy. Create two files Gemfile and config.ru. Here the contents of Gemfile

source :rubygems

gem 'rack-contrib'
gem 'heroku'
gem 'shotgun', :group => :development

Contents of config.ru

require 'bundler'
Bundler.setup
Bundler.require
require 'rack/contrib/try_static'

use Rack::TryStatic, 
    :root => "public",  # static files root dir
    :urls => %w[/],     # match all requests 
    :try => ['.html', 'index.html', '/index.html'] # try these postfixes sequentially
run lambda { [404, {'Content-Type' => 'text/html'}, ['Not Found']]}

Now, we'll init the repository and deploy to Heroku.

cd ~/my_site
bundle install
git init
git add -A
git commit -m 'first commit'
heroku create my-static-blog
git push heroku master

That should be all, time to see how our blog looks like

heroku open

Thanks to Chris Continanza