Search code examples
ruby-on-rails-4rackactiondispatch

Rails 4.2 server; private and public ip not working


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.


Solution

  • 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.