gpt4 book ai didi

ruby-on-rails - Rails 4.2.0.beta2 - 无法连接到 LocalHost?

转载 作者:数据小太阳 更新时间:2023-10-29 07:08:52 26 4
gpt4 key购买 nike

我按照 RailsTutorial.org 第三版(刚刚发布的版本)中的说明安装了 Rails 4.2.0.beta2。我没有使用 cloudIDE,而是在带有 RVM 的 Windows 7 主机上通过 Vagrant 使用 Ubuntu Trusty 32。

rails _4.2.0.beta2_ new hello_app 然后粘贴到 his gemfile sample 中。

在那之后,我跑了:

$ bundle install
$ rails s

服务器启动正常,但是当我尝试连接到 localhost:3000 时,出现“找不到服务器”

更奇怪的是,我还有几个其他的 Rails 入门项目,我一直在使用 Rails 4.0.3 和 4.1.6,我能够很好地连接到那里的服务器。

我在这里错过了什么?为什么当我使用最新版本创建新 Rails 项目时我的浏览器无法连接,但它在旧版本上运行良好?

此外,我尝试了 wget http://0.0.0.0:3000 并在连接并收到 200 响应时未指定长度,而在旧版本下的另一个全新 Rails 应用程序中,我会得到任何 index.html 的实际文件大小。

最佳答案

关于无法访问的服务器,来自 Rails 4.2 release notes :

3.3 Default host for rails server

Due to a change in Rack, rails server now listens on localhost instead of 0.0.0.0 by default. This should have minimal impact on the standard development workflow as both http://127.0.0.1:3000 and http://localhost:3000 would continue to work as before on your own machine.

However, with this change you would no longer be able to access the Rails server from a different machine (e.g. your development environment is in a virtual machine and you would like to access it from the host machine), you would need to start the server with rails server -b 0.0.0.0 to restore the old behavior.

If you do this, be sure to configure your firewall properly such that only trusted machines on your network can access your development server.

127.0.0.1:3000 将仅允许来自端口 3000 上的该地址的连接,而 0.0.0.0:3000 将允许来自任何 端口 3000 的地址。

由于 Rails 4.2 默认只接受来自 localhost 的连接,你只能从 localhost 访问服务器(例如在 VM 内);来自另一台机器(例如 VM 的主机)的连接将不起作用。

您必须使用上述“旧行为”方法来允许来自 VM 主机的连接。


关于未指定的内容长度,这取决于所使用的网络服务器。我假设它使用的是不发送内容长度的分块编码。 Assets 将有内容长度,但没有 HTML。

关于ruby-on-rails - Rails 4.2.0.beta2 - 无法连接到 LocalHost?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26570609/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com