为什么 Ruby on Rails 使用 http://0.0.0.0:3000 而不是 http://localhost:3000? [英] Why does Ruby on Rails use http://0.0.0.0:3000 instead of http://localhost:3000?

查看:136
本文介绍了为什么 Ruby on Rails 使用 http://0.0.0.0:3000 而不是 http://localhost:3000?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Ruby on Rails 的新手,所以当我尝试遵循官方的入门"时ruby on rails 教程,我有点失望,因为它很快就出错了.基本上它说:

<块引用>

...导航到 http://localhost:3000.您应该会看到 Rails 的默认信息页面.

但是当我按照说明进行操作时,我会得到

<上一页>=> Rails 2.3.4 应用程序从 http://0.0.0.0:3000 开始

在尝试了这两个地址之后,我知道它们指向同一个东西,但是有人可以向我解释为什么 Ruby on Rails 使用 http://0.0.0.0:3000 而不是 http://localhost:3000?

有没有办法让 WEBrick 服务器始终使用 localhost?

解决方案

Localhost 的字面意思是您的本地主机",通常由 127.0.0.1 标识,所有到该地址的流量都通过环回接口路由.如果您的 Web 服务器正在侦听 127.0.0.1 上的连接,这意味着它只接受来自同一主机的请求.

0.0.0.0 表示 Rails 正在侦听所有接口,而不仅仅是环回接口.

I am very new to Ruby on Rails so when I tried to follow the official "Getting Started" ruby on rails tutorial, I was a bit disappointed because it went wrong very quickly. Basically it said :

…navigate to http://localhost:3000. You should see Rails’ default information page.

But when I follow the instructions, I get

=> Rails 2.3.4 application starting on http://0.0.0.0:3000

After trying both addresses, I know that they point to the same thing, but can someone explain to me why Ruby on Rails uses http://0.0.0.0:3000 instead of http://localhost:3000?

Is there a way to always have the WEBrick server use localhost?

解决方案

Localhost means quite literally "your local host", usually identified by 127.0.0.1 and all traffic to that address is routed via a loopback interface. If your Web server is listening for connections on 127.0.0.1, this means that it only accepts requests coming from the same host.

0.0.0.0 means that Rails is listening on all interfaces, not just the loopback interface.

这篇关于为什么 Ruby on Rails 使用 http://0.0.0.0:3000 而不是 http://localhost:3000?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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