绑定Rails Server到0.0.0.0是什么? [英] What does binding a Rails Server to 0.0.0.0 buy you?

查看:854
本文介绍了绑定Rails Server到0.0.0.0是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用www.xip.io作为DNS通配符,用于在不同的设备上进行测试。我将我的主域名设置为我的IP地址。我用 bundle exec rails server 启动一个rails服务器,我去这里 www。< ip_address> .xip.io:3000 并注意到我的rails服务器没有响应。

I am using "www.xip.io" as a DNS wildcard for testing on different devices. I set my primary domain to my IP address. I fire up a rails server with bundle exec rails server and I go here www.<ip_address>.xip.io:3000 and notice my rails server doesn't respond.

但是,如果我将rails服务器绑定到0.0.0.0像这样 bundle exec rails server -b 0.0.0.0 ,它的工作原理!我不明白什么是0.0.0.0告诉我的服务器这个工作。有人可以理解吗?

However, if I bind my rails server to 0.0.0.0 like so bundle exec rails server -b 0.0.0.0, it works! I don't understand what 0.0.0.0 is telling my server for this to work. Can someone make sense of this?

推荐答案

绑定到 0.0.0.0 告诉服务绑定到机器上的所有IP地址。默认情况下,Rails服务器用于执行此操作,但4.2更改为仅绑定到 localhost

Binding to 0.0.0.0 tells the service to bind to all IP addresses on your machine. Rails server used to do this by default, but with 4.2 changed to binding only to localhost.

基本上如果是仅限于 localhost ,那么它只会在本地响应 localhost 127.0.0.1 它不能通过DNS服务工作,因为它不是公共IP地址。

Basically if it's only bound to localhost then it will only respond locally to either localhost or 127.0.0.1 which can't work through a DNS service because it's not a public IP address.

当您使用 0.0.0.0 它将绑定到本地主机到您的可路由IP地址。

When you use 0.0.0.0 it will bind to localhost and to your routable IP address.

这篇关于绑定Rails Server到0.0.0.0是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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