Make .local domains NOT slow in macOS

29 January 2018   8 comments   Linux, MacOSX

Problem

I used to have a bunch of domains in /etc/hosts like peterbecom.dev for testing Nginx configurations locally. But then it became impossible to test local sites in Chrome because an .dev is force redirected to HTTPS. No problem, so I use .local instead. However, DNS resolution was horribly slow. For example:

time curl -I http://peterbecom.local/about/minimal.css > /dev/null
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0  1763    0     0    0     0      0      0 --:--:--  0:00:05 --:--:--     0
curl -I http://peterbecom.local/about/minimal.css > /dev/null  0.01s user 0.01s system 0% cpu 5.585 total

5.6 seconds to open a local file in Nginx.

Solution

Here's that one weird trick to solve it: Add an entry for IPv4 AND IPv6 in /etc/hosts.

So now I have:

▶ cat /etc/hosts | grep peterbecom
127.0.0.1       peterbecom.local
::1             peterbecom.local

Verification

Ah! Much better. Thing are fast again:

time curl -I http://peterbecom.local/about/minimal.css > /dev/null
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0  1763    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl -I http://peterbecom.local/about/minimal.css > /dev/null  0.01s user 0.01s system 37% cpu 0.041 total

0.04 seconds instead of 5.6.

Comments

Michał

This is fantastic, thank you!

Jason

Finally! This was killing me. Thank you so much.

Roberto Fierros Z

Huge thanks!

Mihai

This was killing me too. Thank you!

Edgars

Thank you very much!

César Couto

This was actually incredibly helpful.
I was using Prepos to live preview my websites in localhost, actually localhost was okay with prepos it was taking forever to resolve and this fixed my problem.

Floris

Wow, thank you. This made localhost like 3 times faster for me. Awesome!

ivastly

1000x faster for me, many thanks!

Your email will never ever be published

Related posts

Previous:
Even more aggressively trying to preload your next page load 22 January 2018
Next:
Fastest way to unzip a zip file in Python 31 January 2018
Related by Keyword:
uwsgi weirdness with --http 19 September 2019
Bookmarklet to replace the current domain with localhost:8000 17 January 2010
What makes my website slow? DNS 23 October 2009