简体   繁体   English

从传入的针对Heroku Review Apps的DNS请求中解析子域

[英]Parsing the subdomain from incoming DNS requests for Heroku Review Apps

Background 背景

I'm using Heroku's Review Apps feature. 我正在使用Heroku的评论应用功能。 It deploys a new app instance for each github pull request opened, and assigns it a unique URL of the format 它为每个打开的github pull请求部署一个新的应用程序实例,并为其分配格式唯一的URL。

my-app-pr-1234.myapp.herokuapp.com

My app makes heavy use of subdomains, which Heroku doesn't support (see answer here ). 我的应用大量使用了Heroku不支持的子域(请参阅此处的答案)。

They require that I purchase and set up a DNS record to handle the subdomain, so I purchased example.com 他们要求我购买并设置DNS记录以处理子域,因此我购买了example.com

Question

Each pull request will generate it's own unique URL. 每个拉取请求都会生成它自己的唯一URL。 And I don't want to set up a new DNS record for each, I'd rather set up one generic DNS record. 而且我不想为每个设置新的DNS记录,而是希望设置一个通用的DNS记录。

How do I set up DNS so that it "parses" the subdomain of the incoming request and directs it to the correct app? 如何设置DNS,以便它“解析”传入请求的子域并将其定向到正确的应用程序?

Example: 例:

  • I visit foo.pr-1738.example.com 我访问foo.pr-1738.example.com
  • I'd like DNS to parse out the requested subdomain and point to my-app-pr-1738.myapp.herokuapp.com (the subdomain foo will be handled by the app itself) 我希望DNS解析出请求的子域并指向my-app-pr-1738.myapp.herokuapp.com (子域foo将由应用本身处理)

Is this possible? 这可能吗?

Side note: I use DNSimple for DNS record management, although this question applies to DNS in general. 旁注:尽管此问题通常适用于DNS,但我使用DNSimple进行DNS记录管理。

How do I set up DNS so that it "parses" the subdomain of the incoming request and directs it to the correct app? 如何设置DNS,以便它“解析”传入请求的子域并将其定向到正确的应用程序?

You can't, not using simply the DNS protocol, and unless all the hostnames are handled by the same backend server (which you can't really assume as Heroku may route different subdomains set to separate IPs). 您不能,不能仅使用DNS协议,除非所有主机名都由同一台后端服务器处理(您不能真正假定,因为Heroku可能会将设置不同的子域路由到单独的IP)。

If each app has a custom hostname attached and they all follow an unique schema eg <pr-1738>.example.com , then you can create a wildcard 如果每个应用程序都附加了自定义主机名,并且它们都遵循唯一的架构,例如<pr-1738>.example.com ,则可以创建通配符

*.example.com

that points to the main Heroku hostname. 指向主要的Heroku主机名。 Again, this is not guaranteed to always work as Heroku may handle the apps A.example.com and B.example.com from different IPs. 同样,由于Heroku可能会处理来自不同IP的应用程序A.example.com和B.example.com,因此不能保证此方法始终有效。 But it may work in most cases. 但这在大多数情况下可能有效。

Otherwise, the real correct approach would be to provision the appropriate DNS record upon the creation of the app. 否则,真正正确的方法是在创建应用后提供适当的DNS记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM