18

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.

Alexander Sung
  • 325
  • 1
  • 2
  • 7
  • It may be obvious, but have you checked with ps and netstat? – Josh Greifer Nov 15 '12 at 09:08
  • What did you get if your run `wget http://0.0.0.0:3000` ? – Adrien Coquio Nov 15 '12 at 09:31
  • 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 Nov 15 '12 at 09:38
  • 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 lost – Alexander Sung Nov 15 '12 at 09:42
  • 1
    Might also be obvious, but are you starting the server on the same machine as the browser? – moritz Nov 15 '12 at 09:50
  • Yes it's all on my laptop. But it just started working all of a sudden. I don't know what to make of this, but thanks anyways for the help guys. – Alexander Sung Nov 15 '12 at 10:04
  • Suddenly I am having this issue as well. Did anybody get a solution? – Arindam Jan 21 '14 at 10:01
  • @moritz Wow your comment actually helped me out - I didn't realize the shell I was using was SSHed into a virtual machine. – zarak Jul 27 '16 at 02:12

9 Answers9

15

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

Community
  • 1
  • 1
Sivanand Kheti
  • 2,209
  • 1
  • 17
  • 29
15

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

andrewleung
  • 552
  • 6
  • 18
7

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

Seyon
  • 481
  • 6
  • 13
5

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.

MaximeBernard
  • 1,090
  • 1
  • 19
  • 33
  • Thanks this worked for me! I just see there is a missing space here `rails server -b127.0.0.1`, it should be `rails server -b 127.0.0.1` – Tonatiuh Jun 25 '20 at 15:04
1

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

Jeffrey Dabo
  • 207
  • 3
  • 5
0

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.

boulder_ruby
  • 38,457
  • 9
  • 79
  • 100
0

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.

searain
  • 3,143
  • 6
  • 28
  • 60
0

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

puneet18
  • 4,341
  • 2
  • 21
  • 27
0

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