Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection refused to development Rails server

I'm working on a Rails project and for some reason, going to localhost:3000 showed me connection refused, not the site I'm developing. What happened?

like image 375
zrneely Avatar asked Jun 16 '15 20:06

zrneely


4 Answers

Check your host file! By default, Rails only serves to 127.0.0.1. However, I had added additional entries for localhost into my /etc/hosts file (the system takes the last one by default). Since this wasn't 127.0.0.1 (it was the IP of my machine on my private subnet of VM's), Rails wouldn't accept the connection. You could comment out the extra lines in your host file or start the development server with rails s -b 0.0.0.0 to allow any IP to connect to it.

like image 63
zrneely Avatar answered Nov 01 '22 09:11

zrneely


i had the same problem, i tried to restart the server with a different port but the problem persisted

and i found the problem in the hosts file

so try first to connect to the server with ip adress of localhost

127.0.0.1:3000

like image 2
yanddam Avatar answered Nov 01 '22 11:11

yanddam


This is because rails listens only on IPv6 by default, and 127.0.0.1 is IPv4:

$ netstat -ant | grep 3000
tcp6   0  0  ::1.3000      *.*      LISTEN

Connect to ::1:3000

like image 2
zsellera Avatar answered Nov 01 '22 10:11

zsellera


Try a different port:

rails s -p 3001

You might be behind a proxy as well. That could cause issues.

like image 1
user1801879 Avatar answered Nov 01 '22 10:11

user1801879