1

I'm trying to see my Ruby on Rails app on my localhost, when I run rails server it looks like it is running good with no errors but when I open up my localhost at http://localhost:3000/ it redirects me to https://localhost:8080/ and says refuses to connect. I am able to open my localhost files with no problems but when I run rails server and open localhost with the port it redirects me to https instead of http no matter what I do. I even tried running with different ports. I am on Ubuntu and my app is using Puma.

I have done the following so far:

  • Cleared all my cache & history
  • Opened incognito window
  • Ran rails server with different ports
  • Changed some about:config settings to false in firefox
  • Have searched localhost in 'chrome://net-internals/#hstsand' but says not found
  • I've tried the other solutions on this link: Google Chrome redirecting localhost to https

None have worked at all. What could the problem be?

I get this error on Chrome

And this error on Firefox

Any advice on this helps! Thanks.

EDIT: Let me know if this needs to be changed, this is how I have my etc/host/ set up

Lee
  • 11
  • 3
  • Do you have something like nginx running? do you have any other app running that may act like a server? you can try to bind the server to a specific ip and port with something like `rails s -b 0.0.0.0 -p 4000` and you can try to connect to `http://0.0.0.0:4000` for example. Another question, when you do the request, do you see anything on the rails server logs? to discard a puma issue, if the request is not getting there then it's something in the OS settings – arieljuod Jan 20 '21 at 12:07
  • I tried `rails s -b 0.0.0.0 -p 4000` but I still get redirected to `https://localhost:8080/` I don't see any problems in the logs. I'm thinking this might be a problem either in my /etc/hosts settings(not sure how to have them set) or somewhere else because I keep getting redirected to `HTTPS` when I put `HTTP` with a port, which is odd cause I can view all my local host directories, but running with the port doesn't work – Lee Jan 20 '21 at 18:30
  • When I use `curl http://localhost:3000/` or `curl http://0.0.0.0:4000` while running rails server it shows `You are being redirected.` Not sure if that helps but I'm wondering why it redirects me – Lee Jan 20 '21 at 18:47
  • Make you you don't have your app configured as `config.force_ssl = true` for development. https://guides.rubyonrails.org/configuring.html – arieljuod Jan 20 '21 at 21:57
  • Do you see anything on the terminal that's running the rails app when you do a request? to know if the request is reaching rails or if something else is going on. Do you have other apps running? (maybe some docker container, or nginx, or apache) – arieljuod Jan 20 '21 at 22:01
  • Actually I found my issue. I ran `yarn` and then ran `rails s` and my localhost showed up after that! Thanks for helping – Lee Jan 20 '21 at 22:32

1 Answers1

0

After scrolling through posts and much research my issue was that I did not run yarn before running rails server. I found this post and referred to this answer https://stackoverflow.com/a/58369306/14365156

But I did not follow those steps exactly, I only ran yarn then ran rails server and now am finally able to view http://localhost:3000/. Hopefully this helps others!

Lee
  • 11
  • 3