Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
414 views
in Technique[技术] by (71.8m points)

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

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   

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.

UPDATE:

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'

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.)

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:

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...