什么是本地主机,它在哪里定义? [英] What is localhost and where is it defined?
问题描述
我刚刚在 Heroku 的推荐下从 thin
更改为 puma
.当我使用 puma 服务器启动我的 rails 应用程序时,它会响应:<代码>=>启动 Puma=>Rails 4.2.2 应用程序开始在 http://localhost:3000 上开发=>运行 `rails server -h` 以获得更多启动选项=>Ctrl-C 关闭服务器Puma 2.11.3 首发...* 最小线程数:0,最大线程数:16* 环境:开发* 监听 tcp://localhost:3000但是,如果我在浏览器中访问 http://0.0.0.0:3000
,这是我使用瘦服务器的旧本地主机,它不会响应.但是,如果我打开 http://localhost:3000
,则它可以工作.看来localhost的定义变了.
I just changed from thin
to puma
at the recommendation of Heroku. When I start my rails app using the puma server it responds:
=> Booting Puma
=> Rails 4.2.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.11.3 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://localhost:3000
However if I go to http://0.0.0.0:3000
in the browser, which was my old localhost with the thin server, it does not respond. However, if I open http://localhost:3000
, then it works. It appears that the definition of localhost has changed.
那么,localhost
是什么?特别是,它是什么类型的对象,它是如何定义的,我如何看到实际的ip地址,以及为什么puma会改变它?
So, what is localhost
? In particular, what sort of object is it, how is it defined, how do I see the actual ip address, and why does puma change it?
推荐答案
如果你想让 Rails 绑定到不同的 ip,方法是使用 -b
选项.要将其绑定到 0.0.0.0
而不是 Rails-default localhost
,您需要按照 rails s -b 0.0.0.0代码>
If you're trying to get Rails to bind to a different ip, the way to do that is with the -b
option. To bind it to 0.0.0.0
instead of the Rails-default localhost
you'd want to run something along the lines of rails s -b 0.0.0.0
注意:明确地说,将 -p 3000
选项也放入其中(设置端口)可能不是一个坏主意,即使该默认值不太可能改变.也可以通过运行 rails s -h
找到有关可用选项的更多信息.
Note: To be explicit, it may not be a bad idea to throw the -p 3000
option in there too (sets the port), even though that default is not likely to change. More info on the available options can be found by running rails s -h
as well.
这篇关于什么是本地主机,它在哪里定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!