Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
618 views
in Technique[技术] by (71.8m points)

macos - How can I eliminate slow resolving/loading of localhost/virtualhost (a 2-3 second lag) on Mac OS X Lion?

Since setting up my development environments on Mac OS X Lion (brand new macbook air purchased in January 2012), I have noticed that resolving to a virtual host is very slow (around 3 seconds) the first time but after that is fast as long as I continue loading it regularly.

If I leave it untouched for a couple of minutes and then reload again, the first reload is (again) painfully slow; seems like something is being cached.

As can be seen below I am not using the .local TLD.

My setup: Apache 2 - MySQL - PHP installed and enabled - added a couple of virtual hosts one of which I created for localhost

My /etc/hosts:

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost
127.0.0.1       myproject.dev
::1             myproject.dev
fe80::1%lo0     myproject.dev

My virtual host set-up in username.conf:

NameVirtualHost *:80

<Directory "/Users/myusername/Sites/">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /Users/myusername/Dropbox/dev_envs/
</VirtualHost>
<VirtualHost *:80>
    ServerName myproject.dev
    DocumentRoot /Users/myusername/Dropbox/dev_envs/myprojectname
</VirtualHost>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had the exact same problem and it was driving me crazy!

Put all your hosts file entries for localhost into one line like so:

127.0.0.1 localhost myproject.dev myotherproject.dev
::1 localhost
fe80::1%lo0 localhost

Worked like a charm for me. Seems like a bug in Lion.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...