5
votes

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:)

2
Are you able to telnet to the port, try this command telnet localhost 3000Rajdeep Singh
if you are on linux check hosts(cat /etc/hosts) file, it should contains this line 127.0.0.1 localhostKalpesh Fulpagare
Something you'll love is http://lvh.me:3000 -> it's a domain which points to your localhost, so you can test subdomainsRichard Peck

2 Answers

6
votes

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

0
votes

localhost is just an alias for 127.0.0.1

If localhost:3000 doesn't work, but 127.0.0.1:3000 does, it will likely be the case that you don't have the localhost alias set up (in your hosts file), which is what Sabyasachi Ghosh recommended

If you let us know your operating environment, we'll be able to provide more specific advice