Rails 4.2.0.beta2 - 无法连接到 LocalHost? [英] Rails 4.2.0.beta2 - Can't connect to LocalHost?

查看:28
本文介绍了Rails 4.2.0.beta2 - 无法连接到 LocalHost?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I installed Rails 4.2.0.beta2 per the instructions in RailsTutorial.org 3rd Edition (the one that just came out). I'm not using the cloudIDE and am instead using Ubuntu Trusty 32 via Vagrant on a Windows 7 host with RVM.

Did rails _4.2.0.beta2_ new hello_app 然后粘贴在 他的 gemfile 样本.

Did rails _4.2.0.beta2_ new hello_app and then pasted in his gemfile sample.

在那之后,我跑了:

$ bundle install
$ rails s

服务器启动正常,但是当我尝试连接到 localhost:3000 时,我收到找不到服务器"

Server starts fine, however when I try to connect to localhost:3000 I get "Server Not Found"

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

Weirder still, I have a couple other Rails starter projects I've been tinkering with that use Rails 4.0.3 and 4.1.6 and I'm able to connect to the server there just fine.

我在这里错过了什么?为什么当我用最新版本创建了一个新的 Rails 项目时,我的浏览器无法连接,但它在旧版本上可以正常工作?

What am I missing here? Why can't my browser connect when I've created a new Rails project with the latest version, but it works fine with older versions?

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

Also, I tried wget http://0.0.0.0:3000 and while it connected and received a 200 response, the length was unspecified, whereas in another brand new Rails app under an old version, I would get the actual file size of whatever index.html was.

推荐答案

关于无法访问的服务器,来自 Rails 4.2 发行说明:

Regarding inaccessible server, from the Rails 4.2 release notes:

3.3 rails 服务器的默认主机

由于 Rack 中的更改,rails 服务器现在默认侦听 localhost 而不是 0.0.0.0.这应该对标准开发工作流程的影响最小,因为 http://127.0.0.1:3000http://localhost:3000 将继续像以前一样工作你自己的机器.

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.

但是,通过此更改,您将不再能够从不同的机器访问 Rails 服务器(例如,您的开发环境在虚拟机中,而您想从主机访问它),您需要使用 rails server -b 0.0.0.0 启动服务器以恢复旧行为.

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 端口.

127.0.0.1:3000 will only allow connections from that address on port 3000, whereas 0.0.0.0:3000 will allow connections from any address at port 3000.

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

Since Rails 4.2 only accepts connections from localhost by default, you can only access the server from localhost (eg. inside the VM); connections from another machine (eg. VM's host) will not work.

您必须使用旧行为";上述方法允许来自 VM 主机的连接.

You must use the "old behavior" method described above to allow connections from the VM host.

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

Regarding unspecified content length, that depends on the web server in use. I assume it is using chunked encoding which does not send content length. Assets will have content length, but not HTML.

这篇关于Rails 4.2.0.beta2 - 无法连接到 LocalHost?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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