Why is Puma only binding to tcp6? (via `rails s`)

后端 未结 2 443
情歌与酒
情歌与酒 2020-12-20 14:30

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 Loca         


        
相关标签:
2条回答
  • 2020-12-20 15:03

    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.

    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.

    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.

    0 讨论(0)
  • 2020-12-20 15:06

    Running rails like:

    rails s -b 0.0.0.0
    

    works for me. The problem is that "localhost" (the default bind address) bind on IPv4 and IPv6 and the v6 is chosen if both are available. 0.0.0.0 force the use an IPv4 address (also work with 127.0.0.1).

    0 讨论(0)
提交回复
热议问题