但无法连接到localhost

但无法连接到localhost

本文介绍了Rails服务器正在运行,但无法连接到localhost:3000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过railstutorial.org学习Ruby on Rails.从第1章开始,我已经进行了所有设置并运行正常.但是,突然之间,我的下一个应用程序出现了问题.

I am learning Ruby on Rails with railstutorial.orgI had set everything up and working fine from Chapter 1. However, all of a sudden my next app has an issue.

我运行"rails服务器"

I run "rails server"

=> Booting WEBrick
=> Rails 3.2.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-11-15 00:45:08] INFO  WEBrick 1.3.1
[2012-11-15 00:45:08] INFO  ruby 1.9.3 (2012-11-10) [x86_64-linux]
[2012-11-15 00:45:08] INFO  WEBrick::HTTPServer#start: pid=2752 port=3000

似乎工作正常,就像我以前的应用程序一样.

Seems to be working fine, just like with my previous app.

但是,我尝试在各种浏览器上连接到localhost:3000,0.0.0.0:3000,127.0.0.1:3000,但它们都无法建立与服务器的连接.

However, I try connecting to localhost:3000 , 0.0.0.0:3000 , 127.0.0.1:3000 on various browsers and they all cannot establish a connection to the server.

一些注意事项:

-我刚刚能够连接到本地主机-好像突然突然停止工作了.

-I was able to connect to localhost just a while ago--it just seems like it suddenly stopped working out of the blue.

-我的第一个应用程序运行正常,但现在也不适用于我的第一个应用程序.

-My first app was working perfectly fine, but now it doesn't work for my first app either.

-我没有防火墙阻止该端口,并且我的主机文件不是问题.

-I don't have firewalls blocking the port, and my hosts file is not the problem.

-我在Ubuntu 12.10上

-I am on Ubuntu 12.10

我几乎总是通过搜索找到解决方案,但是这次没有..所以我需要一些帮助.我感到非常沮丧,因为我觉得这是一个很简单的问题,我花了太长时间才被困在上面.

I almost always find solutions via search, but not this time.. so I need some help please. It's very frustrating as I feel like it's a simple problem that I spent way too long being stuck on.

谢谢.

推荐答案

,带有rails 4.2.0,默认情况下,服务器绑定到localhost,而不是0.0.0.0.在虚拟盒子中使用滑轨时,从主机访问服务器时,绑定地址必须为0.0.0.0

with rails 4.2.0, the server binds to localhost by default, instead of 0.0.0.0. When working with a rails in a virtual box, accessing the server from the host computer, the binding address needs to be 0.0.0.0

使用-b0.0.0.0启动Rails服务器,以便可以从主机/浏览器访问Rails服务器.

Start rails server with -b0.0.0.0 to make the rails server accessible from the host computer/browser.

http://guides.rubyonrails.org/4_2_release_notes.html#default-host -for-rails-server https://github.com/samuelkadolph/unicorn-rails/issues/12#issuecomment-60875268

这篇关于Rails服务器正在运行,但无法连接到localhost:3000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:57