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

前端 未结 13 776
梦毁少年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:14

    Note: I am using Windows and XAMPP, however while researching the problem many people have had the same issue on Windows and Mac. Answer for reference for anyone finding this question as I have spent hours trying to find a solution that works for me:

    I have tried many solutions for the same problem including putting all of the hosts on one line, removing redundant hosts and virtualhosts, and also including the IPv6 lines - none of these alone were successful.

    The only solution which has so far appeared to work for me is a combination of all of the solutions:

    • Changing the domain I am using from mysite.local to mysite.dev. Inspired by @Cleverlemming's answer.
    • Including the IPv6 lines.
    • Removing redundant virtualhosts and hosts (I commented them out).

    In my hosts file my hosts are currently on separate lines and so far the issue seems to be fixed.

    Good luck to anyone attempting to solve this issue and if anyone has any information to add please do so - this seems to be an issue affected a lot of people with no single known cause or solution.

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

    I've run into this a bunch, too. I have a bunch of vhosts defined on two lines, one for IPv4 and one for IPv6. Moving the host I was trying to resolve to be first in the list sped it up.

    127.0.0.1 faster.example.dev host1.example.dev host2.example.dev host3.example.dev host4.example.dev host5.example.dev host6.example.dev
    ::1 faster.example.dev host1.example.dev host2.example.dev host3.example.dev host4.example.dev host5.example.dev host6.example.dev
    
    0 讨论(0)
  • 2020-12-04 06:22

    Ensuring that the host names are defined at the beginning of the file made the difference for me. By default the line 127.0.0.1 localhost is already at the beginning, just add your entries on the same line.

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

    I had the same problem, also on Lion.

    Strangely, my solution was the opposite of Jeremy's. I had a whole bunch of someproject.dev entries on one line in /etc/hosts. Loading a site on any of them the first time took forever, like a minute or so. If I used it again within 5 seconds or so it was very fast, but much longer and it would again take a minute. I had suspected all sorts of things, mysql connections, Ruby versions, Rails bugs, Apache, Phusion Passenger. Until I finally looked at the Console and realized that DNS lookups were being attempted.

    So, I put all of them on seperate lines:

    127.0.0.1 localhost
    
    127.0.0.1 myproject.dev
    
    127.0.0.1 myotherproject.dev
    

    And suddenly everything was snappy again. Same on both my machines.

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

    There's another issue 10.7.* to 10.8.4 for sites ending in .local which causes five second lookups. Details and solution courtesy Bram Van Damme’s blog post found here.

    “By default, any hostname ending in .local is treated as a Bonjour host rather than by querying the DNS server entries in Network preferences.”

    “To fix this problem (without having to rename each vhost) you need to add IPv6 entries for each of your vhosts in your /etc/hosts file:”

    ::1 mysite.local
    fe80::1%lo0 mysite.local
    127.0.0.1 mysite.local
    
    0 讨论(0)
  • 2020-12-04 06:33

    I had this same problem and finally realized I had the same host entry twice on the same line:

    e.g.

    127.0.0.1 localhost host1 host2 host3 host4 host5 host1 host6
    

    I removed the second instance of the same host (in the example above - host1) - and things immediately sped up.

    Felt a little silly when I discovered this, but when you've got 10 long host names on the same line and you're frequently adding / removing, it can be eaisly overlooked.

    0 讨论(0)
提交回复
热议问题