Rails 4.2 server; private and public ip not working
Asked Answered
F

2

13

I recently updated my rails 4.1.8 to 4.2

I'm not able to access rails app using private ip 192.168.1.x:3000 and also with my public-ip address.

Rails app is working with lvh.me:3000, 0.0.0.0:3000, localhost:3000 and 127.0.0.1:3000. But it looks all the the address are pointing to 127.0.0.1:3000 in my server log rails-issue.

It was working fine in 4.1

I tried adding following in environments/development.rb, but nothing changed.

TRUSTED_PROXIES = %r{
  ^127\.0\.0\.1$                | # localhost
  ^(10                          | # private IP 10.x.x.x
    172\.(1[6-9]|2[0-9]|3[0-1]) | # private IP in the range 172.16.0.0 .. 172.31.255.255
    192\.168                      # private IP 192.168.x.x
   )\.
}x

config.action_dispatch.trusted_proxies = /^127\.0\.0\.1$/ # localhost

I'm trying to point my local server to public ip address. I already configured port forward to access in public address.

Fulmis answered 28/12, 2014 at 10:11 Comment(0)
B
20

The default host for Rails servers has changed in 4.2. It now runs on localhost, which means it'll only accept connections from the host IP. You'll need to run rails server -b 0.0.0.0 to start your server.

Please see the 4.2 release notes, section 3.3 for more details.

Babirusa answered 28/12, 2014 at 16:29 Comment(2)
Thanks @richard. It's working!!. I should have read properly.Fulmis
is there anyway where you can make this standard with 4.2.0. its annoying to type that in every time.Lactescent
E
2

To run as public -b and in a specific port use -p :

rails server -b 0.0.0.0 -p 8520
Emanation answered 20/1, 2015 at 10:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.