Jae
Jae

Reputation: 1157

Rails server refuses to connect in browser

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

Answers (3)

filipe
filipe

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:

  • Reproducibility: A docker container is guaranteed to be identical on any system that can run docker and having a simple file you (and your team members) can run the system with the same specs really fast on another environment.
  • Isolation: Dependencies or settings within a container will not affect any installations or configurations on your computer.
  • Hub: You have thousands of well maintained images available including ruby and you can use them for faster experiment and get in the stuff that mater.
  • Docker is not vagrant, is a lot more and much more powerful.
  • Easy image upgrades: because images are versioned, it's a matter of to change a single tag.

Happy codding with the whale!

Upvotes: 2

Jae
Jae

Reputation: 1157

Resolved by running Ruby on Rails on UBUNTU VirtualBox machine.

Upvotes: 0

tadman
tadman

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

Related Questions