John
John

Reputation: 1123

Vagrant not working with localhost extension on Chrome

I have a 2015 mac with macOs Sierra. After too many problems with apache and php, I've decided to run Vagrant. I'm running box.scotch.io for my work

Before Vagrant I configured the hosts file as follows:

127.0.0.1 devsite.localhost
127.0.0.1 sub.devsite.localhost

Remember I can't change the domains and extensions because it's not my project and I have to use those in order for some redirects and API's to work.

After Vagrant I changed it to:

192.168.33.10 devsite.localhost
192.168.33.10 sub.devsite.localhost

After editing the conf files inside vagrant, it worked fine. BUT not on chrome. I've tested in safari and firefox and it works fine. For some reason, on Chrome those two were still showing me apache2 files. So I've went and deleted the conf files from my local apache (for some reason). The only thing that changed was that now it shows me 403 forbidden (so still apache). I've tried shutting down apache. Now it shows me "This site can't be reached"

I've pinged them and it showed the correct IP (vagrant IP). I've flushed the DNS (from terminal and from chrome) - still doesn't work. I tried restarting chrome - nope. I tried restarting the laptop - nope.

So I thought that chrome dooesn't reload the hosts file, so I changed it from .localhost to .localhost2 or .local . Now it shows me the 404 from vagrant.

The weird part -> Everything i put with .localhost as extension doesn't work on Chrome... a.b.c.localhost will not work. If I start apache, a.b.c.localhost will show me 403 forbidden from apache, even though it's not in the hosts file.

Note that in firefox and safari it works fine. But I really need chrome and the .localhost extension

I've already lost almost 2 days on this issue and I can't afford to lose another one

Upvotes: 7

Views: 1292

Answers (2)

Nikolay Osaulenko
Nikolay Osaulenko

Reputation: 1482

For host management you can use a special plugin https://github.com/devopsgroup-io/vagrant-hostmanager AFAIR they resolved Chrome + MacOS issue

Upvotes: 0

void
void

Reputation: 2799

Find related information here: https://bugs.chromium.org/p/chromium/issues/detail?id=489973

In short: this seem to be a known Chrome feature: /etc/hosts is ignored for resolution of host names ending with .localhost, as OS X specific security mitigation. Comment 22 indicates a workaround: add 127.0.0.1 localhost. into /etc/hosts (and note the trailing dot after "localhost.").

Upvotes: 3

Related Questions