1

i am trying to connect with my application's api using curl http://192.168.1.11:4000/api/v1/login but i always get error curl: (7) Failed to connect to 192.168.1.11 port 4000: Connection refused.

whereas if i am using localhost curl http://localhost:4000/api/v1/login its allowing to connect to server.

Strange thing is i am able to use ip address curl http://192.168.1.11:3000 for my another project without any error.

How can it be worked around.

Bloomberg
  • 2,317
  • 2
  • 25
  • 47
  • 1
    Quick fact: when you are using `http://localhost:4000` its not connecting to `http://192.168.1.11:4000`, its going to `http://127.0.0.1:4000`. (unless obviously you have not messed around with your hosts file) – shivam May 19 '15 at 12:37
  • 1
    Sounds like you bind your application to localhost only – Peter Clause May 19 '15 at 12:37
  • 1
    do you realize you say `3000` in your question and last examples, but `4000` in your first examples? – jrochkind May 19 '15 at 12:39
  • 1
    Are you using rails 4.2 in this application? In that case the server is bound to localhost only. Start your server with `rails s -b0.0.0.0` if you like to have the same behaviour as in rails < 4.2 – Marcus May 19 '15 at 12:40
  • @markus yes i am using rails 4.2 – Bloomberg May 19 '15 at 12:40
  • 1
    @Arvind. It depends on the framework/language you're using. Oh, I see it's rails. Maybe something like this can help: http://stackoverflow.com/questions/28668436/how-to-change-the-default-binding-ip-of-rails-4-2-development-server – Peter Clause May 19 '15 at 12:43

1 Answers1

5

In rails 4.2 they changed the default behaviour to listen only to localhost instead of 0.0.0.0 (everything).

Start your server with:

rails s -b0.0.0.0

and you should be able to access the server using the IP, and not just localhost. If you want to make it permanent and avoid the need to launch the server with -b you can update your bootfile according to this answer: https://stackoverflow.com/a/29562898/839086

Community
  • 1
  • 1
Marcus
  • 12,296
  • 5
  • 48
  • 66