Failing to Connect to Rails Server on VM

I’ve been using vagrant to set up ruby on rails project environment, which is best practice in my opinion. One can perfectly and easily have a clean envrionment, in my case, ubuntu64 to put the whole rails server in while coding in familiar platform using favourite editor.

Usually, I would type in shell the following commands

1
2
3
4
vagrant up
vagrant ssh
cd <project folder>
rails s

the server is up and I can open Chrome on MacOS and type in [project-name].dev:3000 to have a look at the website under development. [project-name].dev is an alias to the IP address of the virtual machine. It’s all beautiful.

However, when I set up a new project today as usual and open up a browser, the server did not respond.

At first I thought it was the rails’s problem. So I tried to connect to the server locally with telnet.

1
2
3
telnet localhost 3000
GET / HTTP/1.0
Content-Type:text/html; charset=UTF-8

which performed perfectly.

It turns out that when I http request [project-name].dev:3000, the server received nothing at all. Though I still don’t get what’s different from the previous ones, I forced the server listen to the ip address on start up and the problem is solved.

1
rails s -b 192.168.34.34

The server listens to http://localhost:3000 by default, then the problem is how the previous ones worked… LOL