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

前端 未结 13 778
梦毁少年i
梦毁少年i 2020-12-04 06:00

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

相关标签:
13条回答
  • 2020-12-04 06:33

    A dumb issue that led me to waste some considerable time: after applying @Cleverlemming's answer, I figured out that there were duplicated entries on the hosts file. Something like:

    ::1          site1.local site2.local site1.local site3.local site4.local
    fe80::1%lo0  site1.local site2.local site1.local site3.local site4.local
    127.0.0.1    site1.local site2.local site1.local site3.local site4.local
    

    Then IP resolving for site3.local and site4.local takes these 5-seconds of death.

    0 讨论(0)
  • 2020-12-04 06:34

    On OSX El Capitan what worked for me was making a duplicate IPv6 entry right above the IPv4 entry like so

    fe80::1%lo0 demo.test.dev
    127.0.0.1   demo.test.dev
    
    0 讨论(0)
  • 2020-12-04 06:34

    The trick that did it for me was adding

    127.0.0.1 locahost
    

    on the first line of the host file.

    From all my virtual hosts, only the ones using a database were slow. I believe it's because the process of looking up "localhost" for the database connection slowed things down, since I only added the addresses for my virtual hosts and not "localhost" as well. Now it's all snappy again. :)

    0 讨论(0)
  • 2020-12-04 06:35

    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.

    0 讨论(0)
  • 2020-12-04 06:37

    Make sure to put the IP v6 entries not in the line with localhost

    ::1 localhost
    

    the IP v6 entries go in a separate line

    fe80::1%lo0 here and_here
    

    It is sometimes really fast now, but there are rare exceptions where the old lags come back. They might however be based on other reasons.

    0 讨论(0)
  • 2020-12-04 06:39

    Specifying same host for IPv6 ::1 helped me.

    127.0.0.1 something.local.mydomain.org
    ::1 something.local.mydomain.org
    
    0 讨论(0)
提交回复
热议问题