Rails 4.2 server; private and public ip not working

微笑、不失礼 提交于 2019-12-18 19:24:48

问题


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.


回答1:


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.




回答2:


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

rails server -b 0.0.0.0 -p 8520


来源:https://stackoverflow.com/questions/27675438/rails-4-2-server-private-and-public-ip-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!