有没有办法控制哪个 CNAME 获取什么内容?

Is there a way to way to control which CNAME gets what content?

我的最终目标是拥有免费计划 cname 内容和高级计划 cname 内容。 例如,如果有人为我的网站设置了 free.example.com 的 cname,我想向他们展示一个特定的页面,如果 premium.example.com 我想向他们展示另一个页面。最后,我想知道是否有办法将新的 cname 添加到我的列表中,以便我可以让他们查看某个页面?

为了让这更容易理解,我想对他们的 cname 和 cname 服务做一些类似 https://www.gitbook.com/ 的事情。

您必须使用用户请求中的 Host header 来识别他们正在访问的子域或 cname,然后向他们显示所需的内容。如果 freepremium 等子域是固定的,您可以使用 Nginx 服务器块或 Apache 虚拟主机将用户定向到特定应用程序或应用程序URI.

同样,您可以获得 Host header 和 req.hostname in Express. Based on the host, you can route the user to the desired content. You can add as much subdomains or cnames you wish and let your application control the content for the user based on the host. If your DNS host has an API (such as Cloudflare),您可以通过编程方式添加您的子域,或者您可以使用通配符子域来接受任何子域。