Slow Web Server On Lion Dns Lookup

15 March 2012

I have been having an issue with my local webserver for a long time, it started half a year ago when I upgraded to Lion. Every time I was doing stuff on my local machine a single request could take up to 20 seconds. That is really annoying when you are developing a website and you need to refresh a lot!

First I was Googling for “Slow Apache OSX Liona lot of people where saying it’s a bad idea to use website.local and it’s better to use website.dev. But because I was already using .dev domains this wasn’t the solution to my problem. Then I found this page.

If you use virtual hosts you have a file /etc/hosts. In this file your computer starts to look when there is a request for a domain name. In this file I found the solution to my problem. This is my hosts file:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1 localhost
fe80::1%lo0	localhost
 
127.0.0.1 twelvetwenty.dev
127.0.0.1 will-it-fit.dev
127.0.0.1 ordnung.dev

And because Apple changed the mechanism used to resolve domain names this problem starts on Lion. IPv6 domains are tried first, than the system queries the external DNS server, and then when it doesn’t find anything it switches back to IPv4 locally. So if you want to fix this, all you need to do is change you hosts file:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1 localhost
fe80::1%lo0	localhost
 
fe80::1%lo0 twelvetwenty.dev
fe80::1%lo0 will-it-fit.dev
fe80::1%lo0 ordnung.dev
 
127.0.0.1 twelvetwenty.dev
127.0.0.1 will-it-fit.dev
127.0.0.1 ordnung.dev

So duplicate you virtual host and put fe80::1%lo0 before every domain!