简体   繁体   English

每个通配符子域指向不同的IP地址

[英]Each wild card sub-domain points to different IP address

I have been using AWS Route-53 as dns service for my application and say in my code, for every http request I have a requirement of creating some dynamic sub-domains and point it to the new ec2 instance that gets created on fly.我一直在为我的应用程序使用 AWS Route-53 作为 dns 服务,并在我的代码中说,对于每个 http 请求,我都需要创建一些动态子域并将其指向动态创建的新 ec2 实例。

Any one should now be able to use the newly created sub-domain to make requests to the newly created ec2 instance.现在任何人都应该能够使用新创建的子域向新创建的 ec2 实例发出请求。

I knew I could use wildcard dns record, but does it not just point to one single IP?我知道我可以使用通配符 dns 记录,但它不只是指向一个 IP 吗?

How could I make every sub-domain that was created to always point to the new ec2 instance?如何使创建的每个子域始终指向新的 ec2 实例?

traefik is exactly what I needed. traefik正是我所需要的。 I configured traefik with etcd as it's provider and just by making entries to etcd server, I could achieve what I wanted.我将 traefik 配置为 etcd 作为它的提供者,只需通过进入 etcd 服务器,我就可以实现我想要的。

Now I just have a wild card domain mapped to an ec2 instance on which I run traefik which watches etcd server for any new entries with /traefik/ as it's prefix.现在我只有一个映射到一个 ec2 实例的通配符域,我在该实例上运行 traefik,它监视 etcd 服务器以查找任何以 /traefik/ 为前缀的新条目。 It then dynamically generates new configuration and takes care of routing any request to the destination server based on the HOST header.然后,它会动态生成新配置,并根据主机header 将任何请求路由到目标服务器。

Create an A record of *.example.com and assign the value to the IP address.创建 *.example.com 的 A 记录并将值分配给 IP 地址。

If any sub domain does not have an explicit record it will default to this record.如果任何子域没有明确的记录,它将默认使用该记录。

Possible solutions for auto adding DNS record.自动添加 DNS 记录的可能解决方案。

  • When creating an EC2 instance add a tag of the domain name(s) that should be assigned to resolve to this instance.创建 EC2 实例时,添加应分配以解析到该实例的域名标签。 Have CloudWatch event detect "StartInstance", then trigger a Lambda to add DNS record via API.让 CloudWatch 事件检测“StartInstance”,然后触发 Lambda 通过 API 添加 DNS 记录。
  • Write a proxy that can determine the IP address to use for each subdomain.编写一个代理,可以确定 IP 地址用于每个子域。 Or instead have it manually added through some kind of automation (SSM/Ansible).或者改为通过某种自动化(SSM/Ansible)手动添加。

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

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