2013-05-04»
Virtual subdomains for open webapps»I’ve been playing around with Firefox’s open web app designs recently. I hadn’t quite realised before that if you have Firefox on Android and your PC, you can run their webapps on FirefoxOS, Android and the desktop, which is pretty impressive. Their payment and push notification infrastructure is exciting too.
One small gotcha is that when you write a webapp, it’s better if you host it on its own individual subdomain (for reasons! Security reasons!).
As it turns out, if you can get your DNS provider to add a line like this to your DNS zone file:
1 |
*.apps.example.com 36000 CNAME www.example.com |
…you can add something like this to your Apache configuration, and create an infinite number of apps in their own domains (so that http://foo.apps.example.com/ would map to pages stored in /var/www/apps/foo )
1 2 3 4 5 6 7 |
<VirtualHost *:80> ServerName apps.example.com ServerAlias *.apps.example.com UseCanonicalName off DocumentRoot /var/www/apps VirtualDocumentRoot /var/www/apps/%1 </VirtualHost> |
You’ll need to enable the mod_vhost_alias module, which you can do in standard Ubuntu and Debian by typing sudo a2enmod vhost_alias
Tada!