简体   繁体   English

Rails 服务器正在运行,但无法连接到 localhost:3000

[英]Rails server is running, but cannot connect to localhost:3000

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.谢谢你。

Try running it in some other port like say 3001 as:尝试在其他端口运行它,比如 3001 为:
rails server -p 3001导轨服务器 -p 3001
If its working than than try it again on 3000 as the command above.如果它的工作比上面的命令在 3000 上再试一次。
I thing some other software is using your 3000 port that's why its not responding.我认为其他一些软件正在使用您的 3000 端口,这就是它没有响应的原因。
Or for some advanced things see here或者一些高级的东西看这里

with rails 4.2.0, the server binds to localhost by default, instead of 0.0.0.0 .使用 rails 4.2.0,服务器默认绑定到localhost ,而不是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,从主机访问服务器时,绑定地址需要为0.0.0.0

Start rails server with -b0.0.0.0 to make the rails server accessible from the host computer/browser.使用-b0.0.0.0启动 rails 服务器,以便从主机/浏览器访问 rails 服务器。

http://guides.rubyonrails.org/4_2_release_notes.html#default-host-for-rails-server https://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

确保在启动 rails 之前运行rake db:create

I'm using rails 5.0.0.beta3 and was running into this issue.我正在使用 rails 5.0.0.beta3 并且遇到了这个问题。 @andrewleung's answer helped me a lot. @andrewleung 的回答对我帮助很大。

It seems like Rails default binding address is messed up on my computer (macOS 10.11.6) ;我的电脑 (macOS 10.11.6) 上的 Rails 默认绑定地址似乎搞砸了; on some others, it works fine.在其他一些情况下,它工作正常。

The simple solution is just to use rails server -b 127.0.0.1 .简单的解决方案是使用rails server -b 127.0.0.1 You can then access your localhost:3000 .然后您可以访问您的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更具体。

I had the same issues and i realized it was in the config/environment/production.rb file where config.assets.compile = false must 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 元素不起作用

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.事实证明我遇到的问题是我的虚拟机硬盘空间不足,甚至没有足够的空间来创建 server.pid 文件。 For some reason though, it wasn't throwing an error for this, as the file was being created, but was left blank.但出于某种原因,它并没有为此引发错误,因为文件正在创建,但被留空。

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 的一个流行原因。

检查您的 /etc/hosts 文件..是 ip 0.0.0.0 或 localhost 指向某个其他地址。

对我来说......我在工作中被代理,不得不做rails s -b 0.0.0.0 -p 3000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法连接到Rails服务器。 本地主机:3000 - I cannot connect to rails server. localhost:3000 无法连接到Localhost:3000 for Rails但127.0.0.1:3000可以工作 - Cannot connect to Localhost:3000 for Rails but 127.0.0.1:3000 works Cloud 9正在运行Rails服务器,但未连接到http:// localhost:3000 - Cloud 9 running rails server, but not connected to http://localhost:3000 Rails服务器不起作用,本地主机:3000 - rails server not working, localhost:3000 Vagrant and Rails服务器:无法连接到本地主机 - Vagrant and Rails server: cannot connect to localhost 无法使用Rails ping http:// localhost:3000 - cannot ping http://localhost:3000 with Rails 并行9 - mac 10.9 - 在Mac上运行的Windows 8.1 rails服务器,如何从Internet Explorer运行localhost:3000? - parallels 9 - mac 10.9 - windows 8.1 rails server running on mac, how to localhost:3000 from internet explorer? Ruby on Rails在Windows上无法连接到localhost:3000、127.0.0.1:3000和0.0.0.0:3000 - Ruby on Rails can't connect to localhost:3000, 127.0.0.1:3000 and 0.0.0.0:3000 on Windows Docker,使用docker flag -p 3000:3000无法从localhost:3000到达“rails server”开发 - Docker, can't reach “rails server” development from localhost:3000 using docker flag -p 3000:3000 在vagrant中无法连接localhost:3000 ruby​​ on rails - can't connect localhost:3000 ruby on rails in vagrant
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM