当我在浏览器中使用0.0.0.0而不是localhost时,Chrome/服务器会做什么? [英] What does Chrome/server do when I use 0.0.0.0 instead of localhost in browser?

查看:92
本文介绍了当我在浏览器中使用0.0.0.0而不是localhost时,Chrome/服务器会做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在webpack开发服务器中运行一个单页应用程序,以便在本地进行热重载.但是,它的后端应用程序不在我的本地计算机上,而是在远程服务器上托管的,例如http://remote-server.com.

I am having a single page application running in webpack dev server for hot reloading on my local. However, the backend application of it was not on my local, it was host in a remote server, say http://remote-server.com.

当我在chrome地址字段中使用以下地址:0.0.0.0:3000/homepage时,http请求(对远程后端服务器的api调用)比使用localhost:3000/homepage慢5倍(甚至更多)

When I use such address in the chrome address field: 0.0.0.0:3000/homepage, the http request (api calls to remote backend server) was 5 times (even more) slower than using localhost:3000/homepage

我真的很困惑为什么会发生这种情况?

I am really confused why would this happen?

实际上,更确切地说,问题是,当我要求Chrome ping 0.0.0.0时,给浏览器/服务器意味着什么,因为0.0.0.0只是用来说绑定到任何可能的地址" '

Actually, more precisely, the question would be, what does it mean to a browser/server when I ask Chrome to ping 0.0.0.0, given the fact that 0.0.0.0 is simply used to say 'bind to any possible address'

http请求就像

get /remote-server.com/api/v1/users
get /remote-server.com/api/v1/products
get /remote-server.com/api/v1/prices

我期望http请求花费相同的时间..当我使用0.0.0.0localhost

I was expecting the http requests takes the same amount of time.. when I use 0.0.0.0 and localhost

推荐答案

当我要求Chrome ping 0.0.0.0时,它对浏览器/服务器意味着什么,因为0.0.0.0只是用来说绑定到任何可能的地址" ?

根据规范 RFC5735 0.0.0.0仅表示源地址",这意味着它是不可路由的地址,不能用于目的地.

By specification RFC5735, 0.0.0.0 only represents "source addresses", which means it is a non-routable address and cannot be used for destination.

但是,出于实际原因,许多客户端软件将0.0.0.0视为localhost .这样的软件列表包括:Chrome,Firefox,Safari,curl,telnet等.因为随着许多Web服务器软件启动并显示诸如在0.0.0.0 ...上监听..."之类的消息,允许访问0.0.0.0对于用户来说非常友好初级开发人员.

However, for practical reason, many client software treat 0.0.0.0 as localhost. Such software list includes: Chrome, Firefox, Safari, curl, telnet etc. Because, as many web server software launch with messages like "listen on 0.0.0.0...", allow visiting to 0.0.0.0 is very user-friendly for junior developers.

实际上,对于Chrome,此行为已作为问题,问题的状态一开始是"WontFix",但后来通过以下解决方案更改为已修复":

Actually, for Chrome, this behavior was discussed as an issue, the issue's status was "WontFix" at the beginning, but later changed to "Fixed" with following solution:

允许显式导航到"0.0.0.0",以支持执行以下操作的系统: 导航到localhost(违反规范...但看似常见).

Allow explicit navigations to "0.0.0.0" to support systems where this performs a navigation to localhost (in defiance of specs... but seemingly common).

这仍然会阻止导航到任何其他以八位字节开头的IP,并且仅 实际以4成分点分四进制形式输入时,允许使用0.0.0.0.

This still prevents navigation to any other IP with leading octet 0, and only allows 0.0.0.0 when it's actually entered in 4-component dotted-quad form.

这篇关于当我在浏览器中使用0.0.0.0而不是localhost时,Chrome/服务器会做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆