Note the following applies to Windows Vista, but is probably easier on MacOS/Linux.
Is your hosts
file becoming monstrous? Do you have an alias or shortcut to your hosts
file because you edit it so often? Tired of manually adding every subdomain and domain you work on?
I was too when I thought there must be a better way. And there was.
The general idea is this: by installing a local DNS nameserver in BIND, we can set up local development domains that look like regular domains on the internet. For real domains, we’ll just forward the requests on to a real nameserver. This gives us a couple more benefits: 1) we can use the local nameserver as a caching nameserver to speed up DNS queries (in theory, I have not actually done this), and 2) we can choose to use any DNS service we wish, i.e. OpenDNS, or Google DNS.
Here are the steps.
C:\Windows\system32\dns
.named.conf
in its entirety.options { directory ";c:\windows\system32\dns\zones"; allow-transfer { none; }; forward only; forwarders { //208.67.222.222; // OpenDNS //208.67.220.220; 8.8.8.8; // Google DNS 8.8.4.4; }; query-source address * port 53; }; /* logging { channel queries_log { file "c:\windows\system32\dns\var\queries.log"; print-severity yes; print-time yes; }; category queries { queries_log ; }; }; */ zone "work.local" IN { type master; file "work.local.txt"; }; key "rndc-key" { algorithm hmac-md5; secret "xxxxxxxxxxxxxxxxxxxxxxxx"; }; controls { inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndc-key"; }; }; |
CNAME
wildcard record.$TTL 86400 @ IN SOA ns1.work.local. admin.work.local. ( 2008102403 10800 3600 604800 86400 ) @ NS ns1.work.local. IN A 127.0.0.1 ns1 IN A 127.0.0.1 www IN A 127.0.0.1 * IN CNAME www |
C:\> ipconfig /flushdns |
www.work.local
. If you have errors, you can uncomment the logging block in named.conf
.VirtualHost
in Apache for your development domain. Thanks to VirtualDocumentRoot
, we can map any number of subdomains to project roots. Here is my VirtualHost
block.<VirtualHost 127.0.0.1> ServerName www.work.local ServerAlias *.work.local VirtualDocumentRoot "C:/_work/%1" <Directory C:/_work> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> |
C:\_work
, for example, C:\_work\awesomeapp
. Create a test index.html file in that directory.Now, you should be able to repeat step 8 for any new website you create! No editing of hosts
files, no bouncing the webserver! Just create the project directory and it’s immediately available.
One other important note: Firefox has its own DNS cache independent of the OS. For sanity, restarting Firefox resets its DNS cache. You can also permanently disable DNS caching in Firefox.