我试图使用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
为我的另一个项目没有任何错误。
如何解决
在rails 4.2中,他们改变了默认行为,只监听localhost
而不是0.0.0.0
(所有)。
启动服务器:
rails s -b0.0.0.0
,您应该能够使用IP访问服务器,而不仅仅是本地主机。如果您想使其永久保存,并且避免使用-b
启动服务器,您可以根据以下答案更新引导文件:https://stackoverflow.com/a/29562898/839086