zrneely
zrneely

Reputation: 1942

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?

Upvotes: 10

Views: 15967

Answers (5)

yang
yang

Reputation: 508

I was unable to connect to local server started in WSL 2 from Windows host machine, I tried everything, then rebooting Windows system magically fixed the problem.

Upvotes: 0

zsellera
zsellera

Reputation: 79

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

Upvotes: 1

yanddam
yanddam

Reputation: 397

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

Upvotes: 2

user1801879
user1801879

Reputation: 822

Try a different port:

rails s -p 3001

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

Upvotes: 2

zrneely
zrneely

Reputation: 1942

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.

Upvotes: 21

Related Questions