Making today worse so tomorrow seems better.

Wildcard DNS and Rails


The most common Rails config wants a separate hostname for each application. If you tend to create new ones frequently, this can mean a lot of running back and forth to your DNS config. At best this means waiting for the changes to propagate, at worst it could mean waiting for corporate IT to get around to it.

Luckily, in addition to normal names, DNS allows you to create “wildcard” records that match any name not otherwise defined.

We setup each hostname with their own wildcard by default, so that foo.hostname is always an alias (CNAME) for hostname.

An example from our bind zone file:
sprocket                    IN      A     
*.sprocket                  IN      CNAME           sprocket

This means that if I want to deploy my new app, The Awesomator, I can use the hostname ‘’ without having to change anything in DNS.

Then I drop my virtual host config awesomator.conf file, largely stolen from Coda Hale’s config , into Apache’s config directory (/etc/apache2/sites-available/ on Debian, /etc/httpd/conf.d/ on Red Hat). An Apache reload and a few mongrels later and I’m up and running on my new hostname.