简体   繁体   English

本地主机、[::1] 和 etc/hosts 中的映射主机有效,但 127.0.0.1 无效

[英]Localhost, [::1], and mapped hosts in etc/hosts work, but 127.0.0.1 does not

The great mystery.伟大的奥秘。 I have an Express/Node (v4.2.2) JS app running on OS X El Capitan.我有一个在 OS X El Capitan 上运行的 Express/Node (v4.2.2) JS 应用程序。 The app is running on port 4444. If I run the app, I'm able to get the proper response back with the following commands:该应用程序在端口 4444 上运行。 如果我运行该应用程序,我可以使用以下命令获得正确的响应:

curl localhost:4444 -> Works curl localhost:4444 -> 作品

curl [::1]:4444 -> Works curl [::1]:4444 -> 作品

curl api.q.com:4444 -> Works curl api.q.com:4444 -> 作品

However, I have a problem with:但是,我有一个问题:

curl 127.0.0.1:4444 -> Doesn't Work; curl 127.0.0.1:4444 ->不起作用; Responds with curl: (52) Empty reply from server响应curl: (52) Empty reply from server

127.0.0.1:4444 fails in all browsers as well. 127.0.0.1:4444在所有浏览器中也失败。 Even more astonishing, api.q.com:4444 works in all browsers EXCEPT for Chrome.更令人惊讶的是, api.q.com:4444适用于Chrome 之外的所有浏览器。

My /etc/hosts file:我的/etc/hosts文件:

127.0.0.1 localhost web.q.com api.q.com qrm.q.com fhr.q.com

::1 localhost

fe80::1%lo0 localhost

I've tried resetting my /etc/hosts file back to the default and flushed my DNS cache.我已经尝试将我的/etc/hosts文件重置回默认值并刷新我的 DNS 缓存。 I have a feeling it might be the app, but I'm not sure what the cause could be.我有一种感觉可能是应用程序,但我不确定原因可能是什么。 Any suggestions?有什么建议?

Turns out, it had something to do with a Linux VM I set up in Virtual Box.事实证明,它与我在 Virtual Box 中设置的 Linux VM 有关。 My /etc/hosts file was the same on that VM (maybe that was the issue?).我的/etc/hosts文件在那个虚拟机上是一样的(也许这就是问题所在?)。

I disabled the VM and everything worked again.我禁用了虚拟机,一切又恢复了。 I have no idea what the cause was, but I'm going to close this question.我不知道原因是什么,但我要结束这个问题。 If anyone else has this issue, I can only suggest look at any VMs you may have running locally.如果其他人有这个问题,我只能建议查看您可能在本地运行的任何 VM。 Thanks again!再次感谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM