Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 889
Ashwin Yaprala Avatar asked Dec 28 '14 10:12

Ashwin Yaprala


2 Answers

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.

like image 123
Rich Seviora Avatar answered Sep 20 '22 12:09

Rich Seviora


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

rails server -b 0.0.0.0 -p 8520
like image 2
errakeshpd Avatar answered Sep 19 '22 12:09

errakeshpd