Rails 4.2 服务器;私人和公共 ip 不起作用 [英] Rails 4.2 server; private and public ip not working

查看:22
本文介绍了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 以及我的 公共 ip 地址 访问 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.但看起来所有地址都指向我服务器日志中的 127.0.0.1:3000 rails-issue.

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.

它在 4.1 中运行良好

It was working fine in 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 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆