Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to Localhost:3000 for Rails but 127.0.0.1:3000 works

I am learning Ruby on Rails with railstutorial.org 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 http://0.0.0.0:3000
=> 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 0.0.0.0:3000 , 127.0.0.1:3000, 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:)

like image 475
yeelan Avatar asked Apr 02 '14 06:04

yeelan


1 Answers

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.

127.0.0.1       localhost

And use localhost:3000 not Localhost:3000

like image 153
Sabyasachi Ghosh Avatar answered Sep 27 '22 00:09

Sabyasachi Ghosh