无法访问curl http:// ip_address:3000

时间:2015-05-19 12:34:45

标签: ruby-on-rails ruby curl

我正在尝试使用curl http://192.168.1.11:4000/api/v1/login连接我的应用程序api,但我总是收到错误curl: (7) Failed to connect to 192.168.1.11 port 4000: Connection refused

如果我使用localhost curl http://localhost:4000/api/v1/login,则允许连接到服务器。

奇怪的是我可以在我的另一个项目中使用ip地址curl http://192.168.1.11:3000而没有任何错误。

如何解决这个问题。

1 个答案:

答案 0 :(得分:5)

在rails 4.2中,他们将默认行为更改为仅收听localhost而不是0.0.0.0(所有内容)。

使用以下命令启动服务器:

rails s -b0.0.0.0

并且您应该能够使用IP访问服务器,而不仅仅是localhost。如果要使其永久化并避免使用-b启动服务器,则可以根据以下答案更新引导文件:https://stackoverflow.com/a/29562898/839086