【问题标题】:Ruby on Rails server started but can't connect to http://localhost:3000Ruby on Rails 服务器已启动但无法连接到 http://localhost:3000
【发布时间】:2016-12-05 19:53:53
【问题描述】:

我是 Ruby on Rails 的新手,正在帮助现有项目。我运行 rails server,并收到以下输出

=> Booting Unicorn
=> Rails 4.2.5.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
I, [2016-12-05T13:44:05.166061 #15228]  INFO -- : listening on addr=0.0.0.0:8080 fd=11
I, [2016-12-05T13:44:05.185700 #15228]  INFO -- : master process ready
I, [2016-12-05T13:44:05.187404 #15242]  INFO -- : worker=0 ready
I, [2016-12-05T13:44:05.187827 #15243]  INFO -- : worker=1 ready
I, [2016-12-05T13:44:05.188412 #15244]  INFO -- : worker=2 ready
^CI, [2016-12-05T13:45:11.233928 #15228]  INFO -- : reaped #<Process::Status: pid 15244 exit 0> worker=2
I, [2016-12-05T13:45:11.234060 #15228]  INFO -- : reaped #<Process::Status: pid 15243 exit 0> worker=1
I, [2016-12-05T13:45:11.234227 #15228]  INFO -- : reaped #<Process::Status: pid 15242 exit 0> worker=0

这似乎表明服务器已启动并正在运行。但是,我无法连接到http://localhost:3000,它给了我一个错误连接被拒绝。有人知道我该如何调试吗?

【问题讨论】:

  • 请粘贴错误信息
  • Rails 版本 4.2.5.2
  • 错误信息是什么?
  • 错误信息:无法访问此站点 localhost 拒绝连接。你的意思是localhost3000.org?在 Google 上搜索 localhost 3000 ERR_CONNECTION_REFUSED
  • 是否在错误中引用了您的数据库?像 ERRNO:::CONNECTION 被拒绝,然后是 pg 或 sqlite 之类的东西?

标签: ruby-on-rails ruby


【解决方案1】:

使用 rails 4.2.0,服务器默认绑定到 localhost,而不是 0.0.0.0。在虚拟盒子中使用rails时,从主机访问服务器,绑定地址需要为0.0.0.0

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

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

或尝试通过不同的端口

rails s -p 3001

【讨论】:

  • 我实际上也尝试了两个 rails s -b 0.0.0.0 -p 3001,但结果相同。
  • 如果您没有问题,请将您的 teamViewer CRED 发送给我 :)
  • 好的,我下载了teamviewer,给你ID和密码?
  • 我在 docker 中运行 rails 时遇到了这个问题。
【解决方案2】:

尝试检查您的主机文件。

Linux /etc/hosts

Windows c:\Windows\System32\drivers\etc\hosts

并编辑本地主机以服务 127.0.0.1。或移动它,使其在最后。 Rails 将最后一次提到 localhost 并使用它。

或者您甚至可以尝试使用telnet localhost 3000 来判断端口是否在 TCP 级别不可用。

我的主机文件看起来像

127.0.0.1       localhost
127.0.1.1       myPC

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback

【讨论】:

  • ## # Host Database # # localhost 用于配置loopback interface # 当系统启动时。不要更改此条目。 ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost 这是我的本地主机文件。
  • 127.0.0.1 localhost # 以下行适用于支持 IPv6 的主机 ::1 ip6-localhost ip6-loopback 这是我的,一切都很好。
猜你喜欢
  • 2015-02-22
  • 1970-01-01
  • 2012-11-03
  • 2014-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-23
  • 1970-01-01
相关资源
最近更新 更多