私人和公共IP不起作用

私人和公共IP不起作用

本文介绍了Rails 4.2服务器;私人和公共IP不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将Rails 4.1.8更新为4.2

I recently updated my rails 4.1.8 to 4.2

我无法使用私有IP 192.168.1.x:3000以及我的public-ip address访问Rails应用.

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

Rails应用程序正在使用lvh.me:30000.0.0.0:3000localhost:3000127.0.0.1:3000.但是看起来所有地址都指向服务器日志 rails-issue 中的127.0.0.1:3000.

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

在4.1中运行正常

我尝试在environments/development.rb中添加以下内容,但没有任何变化.

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

我正在尝试将本地服务器指向公共IP地址.我已经将端口转发配置为可以在公共地址中访问.

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

推荐答案

Rails服务器的默认主机在4.2中已更改.现在,它可以在localhost上运行,这意味着它将仅接受来自主机IP的连接.您需要运行rails server -b 0.0.0.0来启动服务器.

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.

请参阅4.2版本请注意,请参见第3.3节以获取更多详细信息.

这篇关于Rails 4.2服务器;私人和公共IP不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 01:02