17
votes

I am learning Ruby on Rails with railstutorial.org I had set everything up and working fine from Chapter 1. However, all of a sudden my next app has an issue.

I run "rails server"

=> Booting WEBrick
=> Rails 3.2.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-11-15 00:45:08] INFO  WEBrick 1.3.1
[2012-11-15 00:45:08] INFO  ruby 1.9.3 (2012-11-10) [x86_64-linux]
[2012-11-15 00:45:08] INFO  WEBrick::HTTPServer#start: pid=2752 port=3000

Seems to be working fine, just like with my previous app.

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

Some things to note:

-I was able to connect to localhost just a while ago--it just seems like it suddenly stopped working out of the blue.

-My first app was working perfectly fine, but now it doesn't work for my first app either.

-I don't have firewalls blocking the port, and my hosts file is not the problem.

-I am on Ubuntu 12.10

I almost always find solutions via search, but not this time.. so I need some help please. It's very frustrating as I feel like it's a simple problem that I spent way too long being stuck on.

Thank you.

9
It may be obvious, but have you checked with ps and netstat?Josh Greifer
What did you get if your run wget http://0.0.0.0:3000 ?Adrien Coquio
I get: Connecting to 0.0.0.0:3000... connected. HTTP request sent, awaiting response... 200 OK Length: 5906 (5.8K) [text/html]Alexander Sung
Also, ps shows PID TTY TIME CMD 2602 pts/0 00:00:00 bash 2797 pts/0 00:00:00 ps Is my rails server supposed to show up in the processes? I'm leaving it running on one terminal and running these commands on another. Sorry I'm new to Ubuntu/Rails so I'm a bit lostAlexander Sung
Might also be obvious, but are you starting the server on the same machine as the browser?moritz

9 Answers

15
votes

Try running it in some other port like say 3001 as:
rails server -p 3001
If its working than than try it again on 3000 as the command above.
I thing some other software is using your 3000 port that's why its not responding.
Or for some advanced things see here

15
votes

with rails 4.2.0, the server binds to localhost by default, instead of 0.0.0.0. When working with a rails in a virtual box, accessing the server from the host computer, the binding address needs to be 0.0.0.0

Start rails server with -b0.0.0.0 to make the rails server accessible from the host computer/browser.

http://guides.rubyonrails.org/4_2_release_notes.html#default-host-for-rails-server https://github.com/samuelkadolph/unicorn-rails/issues/12#issuecomment-60875268

8
votes

Make sure you run rake db:create before launching rails s.

5
votes

I'm using rails 5.0.0.beta3 and was running into this issue. @andrewleung's answer helped me a lot.

It seems like Rails default binding address is messed up on my computer (macOS 10.11.6) ; on some others, it works fine.

The simple solution is just to use rails server -b 127.0.0.1. You can then access your localhost:3000.

My guess here is (hinted from https://serverfault.com/a/544188) that localhost binding is messed up on my computer whereas 127.0.0.1 is more specific.

1
votes

I had the same issues and i realized it was in the config/environment/production.rb file where config.assets.compile = false must be changed to config.assets.compile = true

However this might in a way render some javascript and sass elements unworking

0
votes

The issue that it turned out I was having was that my VM had run out of hard drive space and there wasn't even enough left to create the server.pid file. For some reason though, it wasn't throwing an error for this, as the file was being created, but was left blank.

0
votes

I run into the same issue. It turned out that browser-sync is also running on localhost:3000.

Due to some Rails developer would use browser-sync to test out the front end scripts quickly, I think that could be a popular reason that port 3000 is used.

0
votes

check your /etc/hosts file..is ip 0.0.0.0 or localhost pointing to some other address.

0
votes

for me...I was behind a proxy at work and had to do rails s -b 0.0.0.0 -p 3000