Monday, January 5, 2009

Personal Web Hosting with App Engine

A few days ago I got a notice from my hosting company that my year long contract has expiring soon. I was using this hosting for three small websites that are 100% static and figured that there should be a cheaper way to get this done.

My first instinct was to look at Amazon S3 as their storage and bandwidth rates are pretty good. For my usage pattern I'd be looking at paying pennies per month to host all three sites. Unfortunately there's one fairly major flaw in web access to S3 that makes hosting an entire website there a non-starter. There is no way currently to set up a S3 bucket to host a file from the root of the bucket (i.e. http://www.jamesbogosian.com/ cannot be set up to serve http://www.jamesbogosian.com/index.html).

After thinking about it some more I realized that even though Google App Engine is designed to host dynamic websites that it could be easily used to suit my needs. Here are the steps that I took to get this working:

  1. Sign up for Google Apps for the domain in question (jamesbogosian.com)
  2. Log into App Engine and create a new application
  3. Download all of the content from jamesbogosian.com and place it in a directory named "static"
  4. Create an app.yaml file at the same level as the static directory that looks like this one (replacing your app ID from step 2 on the first line)
  5. Using appcfg.py from the App Engine SDK (download this if you haven't already), upload your "application" to appspot.com
  6. Log into Google Apps control panel and select "Add more services"
  7. Add your application to this domain by providing the app ID, and choose to host the "application" off of www.yourdomain.com
  8. Add or edit the "www" CNAME on your domain to point to ghs.google.com
  9. In most cases you will also want to redirect your naked domain (i.e. jamesbogosian.com) to www. This is different for each domain registar / DNS set-up. I use GoDaddy, and there was a small trick to get this working (I think)
    1. In the GoDaddy Domain Management tool, set up the forwarding from http://yourdomain.com to http://www.yourdomain.com, as a 301 redirect
    2. In the GoDaddy Total DNS Control and MX Records tool, change the A Record on your domain to point to 64.202.189.170 (this seems to be the way to get forwarding to actually work)


Now, there are a few limitations worth noting:

  • There is a single file size limitation of one meg.

  • There is a file count limitation of 1,000 files. You can work around this by using the zipserve module.

  • Spikes in traffic may currently be greeted with quota errors, but if you're talking about doing real low-traffic hosting I'd imagine that would never happen