this is a situation that's been bugging me a lot the past few days. i have a lot of dev environment subdomains set up in my etc/hosts file like so...
127.0.0.1 localhost
127.0.0.1 sub.localhost
127.0.0.1 another.localhost
127.0.0.1 andanother.localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
and then specified in my Applications/MAMP/conf/apache/extra/httpd-vhosts.conf file, like so...
NameVirtualHost *:80
NameVirtualHost sub.localhost:80
NameVirtualHost another.localhost:80
NameVirtualHost andanother.localhost:80
<VirtualHost *:80>
DocumentRoot "/Users/johndoe/websites"
ServerName localhost
</VirtualHost>
<VirtualHost sub.localhost:80>
DocumentRoot "/Users/johndoe/websites/sub"
ServerName sub.localhost
</VirtualHost>
<VirtualHost another.localhost:80>
DocumentRoot "/Users/johndoe/websites/another"
ServerName another.localhost
</VirtualHost>
<VirtualHost andanother.localhost:80>
DocumentRoot "/Users/johndoe/websites/andanother"
ServerName andanother.localhost
</VirtualHost>
and just recently they all stopped working in Chrome (Firefox & Safari worked just fine). i started getting 404 errors for all of my localhost subdomains.
i just couldn't figure out why Chrome was not resolving those addresses to those directories on my local machine.
.
after a lot of research (and trial and error) i realized it was a DNS issue. previously, my DNS settings in System Preferences > Network > Advanced... > DNS > DNS Servers were as follows...
8.8.8.8
8.8.4.4
xxx.xxx.xxx.x
xxx.xxx.xxx.x
that's Google's DNS servers in the first 2 slots and the x's representing my ISP's DNS server addresses. after some searching some people recommended adding my local network's IP address first, as a way of forcing anything on my system to look locally first before going to outside DNS, so i added my network router's address above the others...
10.0.1.1
and that didn't quite work either - or it did - but didn't last (honestly can't remember now), but what i tried next actually DID work. i added my machine's localhost (home) address above the local network's address, like so...
127.0.0.1
10.0.1.1
8.8.8.8
8.8.4.4
xxx.xxx.xxx.x
xxx.xxx.xxx.x
.
and NOW Google Chrome successfully "finds" all of my localhost subdomains.
i sure hope all of this is helpful for others out there.