简体   繁体   中英

Ruby on Rails: http://localhost:3000 not working

Machines:

  • VM Machine (Ruby on Rails Server) - 192.168.1.37
  • Host Machine (Machine where the VM resides) - 192.168.1.38
  • Remote Machine (Dev Machine) - 192.168.1.36

Notes

  • VM Machine is running Cent OS (console only)
  • Host Machine is running Windows 7
  • VM emulator is Virtual Box
  • Remote Machine is Running on Windows 10

Pre-requisite

  • Added 192.168.1.37 as localhost in the Host Machine host file
  • start the rails service bundle exec rails s -p 3000

Problem

  • accessing site http://localhost:3000 NOT working
  • accessing site https://192.168.1.37:3000 working

What Is Needed

  • Access the site via http://locahost:3000

Quirks

  • It works on remote machines running Linux (changed the host file to point to VM Machine as localhost)

why do you insist to visit the site via localhost:3000? as you are running the app under vm, if you want to access the webpage from another pc/mac via ip, you have to forward the local port to the vm port via nat, or let the vm to own a ip from your local network.

As you can access the webpage via https://192.168.1.37:3000 , rails is running, there's nothing to do with rails configurations.

Rails 4 binds on localhost by default, so you will need to bind to 0.0.0.0 , if you want the page to be accessible from another machine.

Start your rails server like this:

bundle exec rails s -p 3000 -b 0.0.0.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM