使用Puma和指向127.0.0.1的域名的"rails服务器" [英] `rails server` using Puma and domain name pointing to 127.0.0.1

查看:92
本文介绍了使用Puma和指向127.0.0.1的域名的"rails服务器"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用子域的Rails应用程序(旧版应用程序,我一直想更改).我将应用程序部署到了Heroku,并开始测试 Puma ,因为这是Heroku的推荐选择,Rails即将发布.当我在本地使用WEBrick时,我能够使用指向127.0.0.1的DNS记录(例如vcap.me,特别是 http://abcde.vcap.me:3000/会将subdomian正确设置为"abcde" .

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

只需将 gem'puma'添加到我的Gemfile并运行捆绑包,就会导致 rails服务器启动 Puma .除非所有测试域都不起作用: http://localhost:3000/起作用,但

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只是说:此网页无法使用ERR_CONNECTION_REFUSED"

Chrome simply says: "This webpage is not available ERR_CONNECTION_REFUSED"

Firefox:无法连接Firefox无法通过vcap.me:3000与服务器建立连接...."

Firefox: "Unable to connect Firefox can't establish a connection to the server at vcap.me:3000. ..."

我尚未找到原因/解决方案,但我怀疑这与Puma支持的非HTTP TCP请求有关,除非知道,我只是通过浏览器尝试HTTP请求.

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.

只是出于好奇,如果您还没有听说过vcap.me和类似的域,那只是指向本地主机的DNS记录:

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

推荐答案

这是问题#782在2016年7月18日解决的Puma服务器中此处.

This was issue #782 in the Puma server that was solved on July 18, 2016 here.

您对诸如 vcap.me 之类的域的使用不是问题.该域由DNS服务器解析为 127.0.0.1 .问题是,在修复之前,Puma在某些系统上默认情况下仅绑定到 localhost 的IPv6分辨率,即 :: 1 .由于 vcap.me 不提供IPv6分辨率,因此您无法通过调用 http:来访问Puma://vcap.me:3000/.

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

您发现 rails服务器-p 3000 -b vcap.me 解决了该问题,是因为它等效于 rails服务器-p 3000 -b 127.0.0.1 .之后,服务器地址与 vcap.me 的仅IPv4名称解析匹配.

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.

无论如何,这是过去的问题.现在默认情况下,Puma绑定到 localhost 的IPv4和IPv6分辨率.

Anyway, it's an issue of the past. Now by default, Puma binds to both the IPv4 and IPv6 resolutions of localhost.

这篇关于使用Puma和指向127.0.0.1的域名的"rails服务器"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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