如何将自定义域指向Heroku子域? [英] How to point a custom domain to a Heroku subdomain?
问题描述
是否可以允许用户使用自己的自定义域来指向特定的Heroku子域?我正在使用允许我的应用使用abc.myapp.com URL的通配符子域.用户可以添加myuser.com并指向它吗?如何才能做到这一点?
Is it possible to allow users to use their own custom domains to point to a specific Heroku subdomain? I'm using wildcard subdomains that allow my app to use abc.myapp.com URL's. Could a user add myuser.com and point to that? How can this be done?
尝试添加CNAME指向该位置会返回Heroku |没有此类应用程序消息,当我将自定义域添加到Heroku仪表板时,它仅指向顶级域.
Trying to add CNAME to point there returns Heroku | No such app messages and when I add the custom domain to the Heroku Dashboard it just points to the top level domain.
详细步骤:
CNAME mydomain.com ---> myapp.herokuapp.com-运行正常
CNAME mydomain.com ---> myapp.herokuapp.com -- works fine
CNAME anotherdomain.com ---> sub.mydomain.com-不起作用
CNAME anotherdomain.com ---> sub.mydomain.com -- not working
如果我将另一个domain.com添加到Heroku仪表板,则:
If I add anotherdomain.com to the Heroku dashboard then:
CNAME anotherdomain.com ---> sub.mydomain.com或mydomain.com-可以正常工作,但在两种情况下都可以打开根域mydomain.com
CNAME anotherdomain.com ---> sub.mydomain.com or mydomain.com -- works fine but opens the root domain mydomain.com in either cases
因此,我想提供适当子域的唯一方法是在我的应用程序中处理它,以便数据库中的anotherdomain.com对应于sub.mydomain.com并提供适当的页面.
So I guess the only way to serve the proper subdomain is to handle it inside my app, so that anotherdomain.com in the db corresponds to sub.mydomain.com and serve the proper page.
推荐答案
在您的应用程序代码中,您需要配置该新域以指向您的应用程序.
这是使用heroku domains:add
命令手动执行的操作.
In your app's code, you need to configure that new domain to point to your app.
This is what you would manually be doing with the heroku domains:add
command.
使用 heroku的平台API ,您可以通过编程方式执行此操作
Using heroku's Platform API, you can perform this programmatically.
这篇关于如何将自定义域指向Heroku子域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!