Ruby-on-rails Rails 服务器正在运行,但无法连接到 localhost:3000
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13394238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails server is running, but cannot connect to localhost:3000
提问by Alexander Sung
I am learning Ruby on Rails with railstutorial.org I had set everything up and working fine from Chapter 1. However, all of a sudden my next app has an issue.
我正在通过 railstutorial.org 学习 Ruby on Rails 我已经在第 1 章中设置了一切并且工作正常。但是,突然间我的下一个应用程序出现了问题。
I run "rails server"
我运行“rails服务器”
=> 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.
似乎工作正常,就像我以前的应用程序一样。
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.
但是,我尝试在各种浏览器上连接到 localhost:3000 、 0.0.0.0:3000 、 127.0.0.1:3000 ,但它们都无法与服务器建立连接。
Some things to note:
一些注意事项:
-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.
- 我没有阻止端口的防火墙,我的主机文件不是问题。
-I am on Ubuntu 12.10
-我在 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.
我几乎总是通过搜索找到解决方案,但这次不是。所以我需要一些帮助。这非常令人沮丧,因为我觉得这是一个简单的问题,我花了很长时间被困在这个问题上。
Thank you.
谢谢你。
回答by andrewleung
with rails 4.2.0, the server binds to localhostby 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
使用 rails 4.2.0,服务器localhost默认绑定到,而不是0.0.0.0. 在虚拟盒子中使用rails,从主机访问服务器时,绑定地址需要为0.0.0.0
Start rails server with -b0.0.0.0to make the rails server accessible from the host computer/browser.
启动 rails server-b0.0.0.0使 rails server 可以从主机/浏览器访问。
http://guides.rubyonrails.org/4_2_release_notes.html#default-host-for-rails-serverhttps://github.com/samuelkadolph/unicorn-rails/issues/12#issuecomment-60875268
http://guides.rubyonrails.org/4_2_release_notes.html#default-host-for-rails-server https://github.com/samuelkadolph/unicorn-rails/issues/12#issuecomment-60875268
回答by Sivan
Try running it in some other port like say 3001 as:
rails server -p 3001
If its working than than try it again on 3000 as the command above.
I thing some other software is using your 3000 port that's why its not responding.
Or for some advanced things see here
尝试在其他端口运行它,比如 3001 为:
rails server -p 3001
如果它工作比上面的命令在 3000 上再试一次。
我认为其他一些软件正在使用您的 3000 端口,这就是它没有响应的原因。
或者一些高级的东西看这里
回答by Seyon
Make sure you run rake db:createbefore launching rails s.
确保rake db:create在启动 rails 之前运行。
回答by MaximeBernard
I'm using rails 5.0.0.beta3 and was running into this issue. @andrewleung's answer helped me a lot.
我正在使用 rails 5.0.0.beta3 并且遇到了这个问题。@andrewleung 的回答对我帮助很大。
It seems like Rails default binding address is messed up on my computer (Mac OS 10.11.6) ; on some others, it works fine.
我的电脑(Mac OS 10.11.6)上的 Rails 默认绑定地址似乎搞砸了;在其他一些情况下,它工作正常。
The simple solution is just to use rails server -b127.0.0.1. You can then access your localhost:3000.
简单的解决方案就是使用rails server -b127.0.0.1. 然后您可以访问您的localhost:3000.
My guess here is (hinted from https://serverfault.com/a/544188) that localhost binding is messed up on my computer whereas 127.0.0.1 is more specific.
我的猜测是(从https://serverfault.com/a/544188暗示)我的计算机上的 localhost 绑定搞砸了,而 127.0.0.1 更具体。
回答by Jeffrey Amoah
I had the same issues and i realized it was in the config/environment/production.rbfile where config.assets.compile = falsemust be changed to config.assets.compile = true
我遇到了同样的问题,我意识到它config/environment/production.rb在config.assets.compile = false必须更改为的文件中config.assets.compile = true
However this might in a way render some javascript and sass elements unworking
然而,这可能会以某种方式呈现一些 javascript 和 sass 元素不起作用
回答by Aaron Moreno
for me...I was behind a proxy at work and had to do rails s -b 0.0.0.0 -p 3000
对我来说......我在工作中被代理人支持并且不得不做 rails s -b 0.0.0.0 -p 3000
回答by boulder_ruby
The issue that it turned out I was having was that my VM had run out of hard drive space and there wasn't even enough left to create the server.pid file. For some reason though, it wasn't throwing an error for this, as the file was being created, but was left blank.
事实证明我遇到的问题是我的虚拟机硬盘空间不足,甚至没有足够的空间来创建 server.pid 文件。但出于某种原因,它并没有为此引发错误,因为文件正在创建,但被留空。
回答by searain
I run into the same issue. It turned out that browser-sync is also running on localhost:3000.
我遇到了同样的问题。原来,浏览器同步也在 localhost:3000 上运行。
Due to some Rails developer would use browser-sync to test out the front end scripts quickly, I think that could be a popular reason that port 3000 is used.
由于一些 Rails 开发人员会使用浏览器同步来快速测试前端脚本,我认为这可能是使用端口 3000 的一个流行原因。
回答by puneet18
check your /etc/hosts file..is ip 0.0.0.0 or localhost pointing to some other address.
检查您的 /etc/hosts 文件..是 ip 0.0.0.0 还是 localhost 指向某个其他地址。

