问题
I have a Rails application that uses subdomains (legacy application, I've been wanting to change that, not yet). I deployed my app to Heroku and I've started to test Puma because it's the recommended choice for Heroku and the default in the upcoming release of Rails. When I used WEBrick (locally) I was able to test my subdomains using a DNS record that pointed to 127.0.0.1 such as vcap.me, specifically http://vcap.me:3000/ would point to my app and http://abcde.vcap.me:3000/ will correctly set the subdomian to "abcde"
.
Simply adding gem 'puma'
to my Gemfile and runnning bundle, causes rails server
to start Puma. Except none of the test domains work: http://localhost:3000/ works, but not http://vcap.me:3000/ or http://lvh.me:3000/
Chrome simply says: "This webpage is not available ERR_CONNECTION_REFUSED"
Firefox: "Unable to connect Firefox can't establish a connection to the server at vcap.me:3000. ..."
I haven't found a cause/solution, but I suspect it has to do with non HTTP TCP requests supported by Puma, except right know, I'm simply trying a HTTP request through the browser.
Just for the curious, if you haven't heard about vcap.me and similar domains, it's simply a DNS record that points to localhost:
$ dig vcap.me
...
vcap.me. 3048 IN A 127.0.0.1
...
$ dig a.vcap.me
...
a.vcap.me. 3600 IN A 127.0.0.1
...
回答1:
I feel ashamed, @maxd posted a solution to a very similar question: https://stackoverflow.com/a/28745407/637094 and it works. I still don't understand why I need to bind to vcap.me and I didn't before when I used WEBrick.
rails server -p 3000 -b vcap.me
I'll leave the question open, so maybe someone can expand and we all get a better picture of what's going on
回答2:
This was issue #782 in the Puma server that was solved on July 18, 2016 here.
Your use of domains like vcap.me
was not the issue. That domain be resolved to 127.0.0.1
by the DNS server. The issue was, before it was fixed, that on some systems Puma would by default bind only to the IPv6 resolution of localhost
, i.e. ::1
. Since vcap.me
does not provide a IPv6 resolution, you could not reach Puma by calling http://vcap.me:3000/.
Your observation that rails server -p 3000 -b vcap.me
solved the issue is because that is equivalent to rails server -p 3000 -b 127.0.0.1
. After that, the server's address matched the IPv4-only name resolution of vcap.me
.
Anyway, it's an issue of the past. Now by default, Puma binds to both the IPv4 and IPv6 resolutions of localhost
.
来源:https://stackoverflow.com/questions/35000405/rails-server-using-puma-and-domain-name-pointing-to-127-0-0-1