Slow web server on Lion (DNS lookup)
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 Lion” a 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!
THE COMMENTS:
What Bjorn said 55 days later:
There is a very simple and nice Ruby gem for that:
https://github.com/bjeanes/ghost
What Sparrow said 96 days later:
Thanks – this was driving me crazy! I thought I’d configured http.conf incorrectly and was wasting hours trying to resolve it.
What Wouter Hisschemöller said 221 days later:
Hoi Jankees,
Dit is de oplossing! Werkt prima. Net vorige week de Lion update gehad en apache is nu weer snel.
What Daniel Bakker said 330 days later:
Dank voor het delen!
Ik werk al enige tijd op Lion maar sinds vorige week na een update vanuit apple had ik ineens een delay van 5sec per request. Host file aangepast naar bovenstaande en alles is weer super snel!
Thx, Daniel