What is localhost and where is it defined?

3.6k views Asked by At

I just changed from thin to puma at the recommendation of Heroku. When I start my rails app using the puma server it responds: => Booting Puma => Rails 4.2.2 application starting in development on http://localhost:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server Puma 2.11.3 starting... * Min threads: 0, max threads: 16 * Environment: development * Listening on tcp://localhost:3000 However if I go to http://0.0.0.0:3000 in the browser, which was my old localhost with the thin server, it does not respond. However, if I open http://localhost:3000, then it works. It appears that the definition of localhost has changed.

So, what is localhost? In particular, what sort of object is it, how is it defined, how do I see the actual ip address, and why does puma change it?

2

There are 2 answers

0
jimcavoli On BEST ANSWER

If you're trying to get Rails to bind to a different ip, the way to do that is with the -b option. To bind it to 0.0.0.0 instead of the Rails-default localhost you'd want to run something along the lines of rails s -b 0.0.0.0

Note: To be explicit, it may not be a bad idea to throw the -p 3000 option in there too (sets the port), even though that default is not likely to change. More info on the available options can be found by running rails s -h as well.

1
Richard Hamilton On

Localhost is the IPv4 loopback IP address 127.0.0.1. It is used instead of the hostname of a computer. Localhost can sometimes mean this computer.

For example, directing a web browser installed on a system running an HTTP server to http://localhost will display the home page of the local website.

Here's an interesting Wikipedia article

https://en.wikipedia.org/wiki/Localhost