为什么Puma仅绑定到tcp6

为什么Puma仅绑定到tcp6

本文介绍了为什么Puma仅绑定到tcp6? (通过`rails s`)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全新生成的Rails 4.2.0项目.跑rails s,使用WEBrick的行为符合预期:

Brand new generated Rails 4.2.0 project. Ran rails s, behaved as expected using WEBrick:

vagrant@web1:~$ netstat -nlpt
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:3000          0.0.0.0:*               LISTEN      27158/ruby2.1
tcp6       0      0 ::1:3000                :::*                    LISTEN      27158/ruby2.1

将puma添加到Gemfile中,运行捆绑软件,然后再次rails s;想出了Puma,但只绑定了tcp6接口,而不是tcp:

Added puma to Gemfile, ran bundle, then rails s again; came up with Puma, but only bound tcp6 interface, not tcp:

vagrant@web1:~$ netstat -nlpt
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp6       0      0 ::1:3000                :::*                    LISTEN      27116/ruby2.1

任何线索为何?我一直在搜索,没有运气.

Any clue why? I've been googling with no luck.

更新:

运行puma -b tcp://0.0.0.0:3000可行.但是,将bind指令添加到config/puma.rb并运行rails s不会:

Running puma -b tcp://0.0.0.0:3000 works. However, adding the bind directive to config/puma.rb and running rails s doesn't:

bind 'tcp://0.0.0.0:3000'

但是,我的配置文件中的threads/workers指令正在运行,因此,我知道配置文件正在被加载和使用. (当然,甚至添加了puts语句.)

The threads/workers directives in my config file are working, however, so I know the config file is getting loaded and used. (Even added a puts statement to be sure.)

如果我只是运行puma,绑定到正确的接口,甚至会获取配置文件.我可能只需要运行puma而不是rails s,即使这很烦人并且必须将其添加到我的开发人员文档中.

The config file even gets picked up if I just run puma, binding to the correct interface. I may just have to resort to running puma instead of rails s, even though it's annoying and has to be added to my developer docs.

UPDATE2:

我误会了.运行rails s不会自动启动config/puma.rb.仍在调查...

I was mistaken. Running rails s does not pick up config/puma.rb automatically. Still investigating...

推荐答案

您看到的问题是Puma默认绑定到localhost.基础的Rails TcpServer将其视为普通的主机名,并且只能解析为一个IP地址(在您的情况下为IPv6版本),而不能同时解析为IPv4和IPv6版本.

The problem you see is that Puma by default binds to localhost. This was treated as a normal hostname by the underlying Rails TcpServer and there resolved to only one IP address (the IPv6 version in your case) but not to both the IPv4 and IPv6 versions.

彪马(Puma)#782 解决了,于2016年7月18日使用此补丁.在当前版本中,专门针对localhost的例外,该例外现在绑定到IPv4和IPv6分辨率.

This was treated in Puma issue #782 and solved on July 18, 2016 with this patch. In current versions, an exception is made specifically for localhost, which now binds to both the IPv4 and IPv6 resolutions.

对于所有其他域,Puma仍将绑定到系统名称解析返回的 first IP地址.在这些情况下,您至少可以通过在/etc/hosts中添加适当的条目来选择是否要让Puma绑定到IPv4或IPv6分辨率.

For all other domains, Puma will still bind to the first IP address returned by the system's name resolution. In these cases, you can at least choose if you want Puma to bind to the IPv4 or IPv6 resolution by adding an appropriate entry to /etc/hosts.

这篇关于为什么Puma仅绑定到tcp6? (通过`rails s`)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:54