2015-05-19 28 views
1

我正嘗試使用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無法訪問curl http:// ip_address:3000

而如果我使用本地主機curl http://localhost:4000/api/v1/login它允許連接到服務器。

奇怪的是我能夠使用IP地址curl http://192.168.1.11:3000爲我的另一個項目沒有任何錯誤。

它是如何解決的。

+1

快速的事實:當你使用'http:// localhost:4000'它沒有連接到'http://192.168.1.11:4000',它將轉到'http://127.0.0.1:4000'。 (除非顯然你沒有搞亂你的hosts文件) – shivam

+1

聽起來像你綁定你的應用程序到localhost只有 –

+1

你知道你在你的問題和最後的例子中說'3000',但在你的第一個例子中'4000'? – jrochkind

回答

5

在導軌4.2中,他們改變了默認行爲,只聽取localhost而不是0.0.0.0(全部)。

與啓動服務器:

rails s -b0.0.0.0 

,你應該能夠訪問使用IP的服務器,而不僅僅是本地主機。如果你想使它永久存在,並避免需要啓動服務器-b你可以根據這個答案更新你的啓動文件:https://stackoverflow.com/a/29562898/839086

+0

完全工作兄弟.. .. – Prem

相關問題