Why does Ruby on Rails use http://0.0.0.0:3000 instead of http://localhost:3000?

后端 未结 8 1250
醉话见心
醉话见心 2020-12-13 04:00

I am very new to Ruby on Rails so when I tried to follow the official \"Getting Started\" ruby on rails tutorial, I was a bit disappointed

相关标签:
8条回答
  • 2020-12-13 04:25

    Actually rails has different configuration options about if it listens to something specific or all interfaces.

    0 讨论(0)
  • 2020-12-13 04:27

    For those of us using Nitrous.io virtual server envrionment for development, I believe we have to bind to 0.0.0.0 as there is no localhost per se.

    0 讨论(0)
  • 2020-12-13 04:29

    0.0.0.0 means all interfaces. Including 127.0.0.1 a.k.a. localhost.

    0 讨论(0)
  • 2020-12-13 04:35

    Just so everyone knows, my firefox browser correctly displays the locally hosted server if I access http://localhost:3000/ but it does NOT display when I attempt to access http://0.0.0.0:3000/ as recommended by Ruby. Clearly, in some sense, they are not equivalent.

    I'm on Windows btw.

    0 讨论(0)
  • 2020-12-13 04:40

    If you want localhost, one quick way is to specify the binding rails s -blocalhost (and the port with -pNNNN, more options with rails s --help).

    My server started running by default on localhost for reasons to be investigated. As a result lvh.me stopped working, preventing me from specifying subdomains (eg: www.lvh.me:3000).

    I "solved" this specifying the binding:

    rails s -b0.0.0.0 # will work with lvh.me
    
    0 讨论(0)
  • 2020-12-13 04:42

    Localhost means quite literally "your local host", usually identified by 127.0.0.1 and all traffic to that address is routed via a loopback interface. If your Web server is listening for connections on 127.0.0.1, this means that it only accepts requests coming from the same host.

    0.0.0.0 means that Rails is listening on all interfaces, not just the loopback interface.

    0 讨论(0)
提交回复
热议问题