Ruby-on-rails – Cannot connect to Localhost:3000 for Rails but works


I am learning Ruby on Rails with and met this strange problem.

I ran "rails server" and the following information showed:

=> Booting WEBrick
=> Rails 4.0.4 application starting in development on
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-04-02 01:28:18] INFO  WEBrick 1.3.1
[2014-04-02 01:28:18] INFO  ruby 2.0.0 (2014-02-24) [x86_64-darwin12.5.0]
[2014-04-02 01:28:18] INFO  WEBrick::HTTPServer#start: pid=13004 port=3000

I try connecting to localhost:3000 on various browsers and they all cannot establish a connection to the server.

I also tried rails server -p 3001 and connect to localhost:3001, which failed as well.

However, I tried ,, both of them worked and rendered the default welcome for rails.

Then I tried localhost:80, which successfully told me "It Works" and I can actually connect to my another local project using PHP+Apache.

So I really wonder why this happens and could anyone possibly give me any hint on it.

Thank you in advance:)

Best Solution

Please check your host file. I assume you are using ubuntu then just type

sudo nano /etc/hosts

If the below line exists then ok else just insert the line.       localhost

And use localhost:3000 not Localhost:3000

Related Question