Reputation: 1157
I'm just trying to run my server locally. I'm on Windows and using Ruby on Rails on Windows is a pain, so I am using Vagrant. I am doing all of these commands from my Vagrant shell.
I've tried rails s
and rails s -b 0.0.0.0
. Both give me OK responses in the terminal:
=> Rails 5.2.3 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.1 (ruby 2.6.1-p33), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
However, when I go to localhost:3000
in my browser, it gives me:
This site can't be reached.
localhost refused to connect.
When I tried to curl http://localhost:3000
get:
curl: (7) Failed to connect to localhost port 3000: Connection refused
I also have the following line of code in my Vagrantfile:
config.vm.network "forwarded_port", guest: 3000, host: 3000
Really don't know what to do next. Right now, I am installing Ubuntu ISO file (will be done in 5 hours, so that's quite a bit of time) to create a VirtualBox instance as backup if this doesn't work. Hoping I can find a fix for this.
Upvotes: 3
Views: 2869
Reputation: 2047
I would like to suggest you docker. Docker is not new, it was released in 2012 and since then has become one of the fastest-growing technologies in web development and devops.
Some of the advantages you will have if you start using it:
Happy codding with the whale!
Upvotes: 2
Reputation: 211720
The key thing here is "localhost" on your Vagrant box and "localhost" on your machine are two different things. The port forwarding can often fix this, but if you have two Vagrant machines using the same port you may be sending traffic to the wrong one.
It's often better to get the Vagrant machine's IP and connect to that directly. If that IP keeps changing, you can lock it down:
config.vm.network "private_network", ip: "172.30.1.5"
Then you connect to http://172.130.1.5:3000/
predictably.
Upvotes: 1