乐闻世界logo
搜索文章和话题

How to point subdomain to a Heroku app, and root domain to another Heroku app?

1个答案

1

This typically involves configuring the DNS (Domain Name System) and some settings on Heroku. The following are the steps and examples:

1. Preparation

Ensure you have two Heroku applications, such as app1.herokuapp.com and app2.herokuapp.com. Additionally, ensure you have purchased a domain, such as example.com.

2. Configure the Root Domain

First, configure the root domain (example.com) to point to one of the Heroku applications (e.g., app1.herokuapp.com):

  1. Add a Custom Domain to the Heroku Application:

    • Log in to the Heroku Dashboard.
    • Select your application (e.g., app1).
    • Navigate to "Settings" > "Domains and certificates" > "Add domain".
    • Add your root domain (example.com).
  2. Configure DNS Provider:

    • Log in to your domain registrar or DNS provider's control panel.
    • Set up an ALIAS or ANAME record (if supported by your DNS provider) pointing to app1.herokuapp.com. If not supported, you can set multiple A records pointing to the IP addresses provided by Heroku for your root domain.

3. Configure the Subdomain

Next, configure the subdomain (e.g., sub.example.com) to point to another Heroku application (e.g., app2.herokuapp.com):

  1. Add a Custom Domain to Another Heroku Application:

    • Repeat the above step 1, but this time add the domain sub.example.com to app2.
  2. Configure DNS Provider:

    • In the DNS settings, add a CNAME record for sub.example.com pointing to app2.herokuapp.com.

Example

Assuming your DNS provider supports ALIAS records:

  • Root Domain (example.com):

    • Type: ALIAS
    • Name: example.com
    • Value: app1.herokuapp.com
  • Subdomain (sub.example.com):

    • Type: CNAME
    • Name: sub
    • Value: app2.herokuapp.com

Notes

  • DNS changes may take some time (typically a few minutes to several hours) to propagate globally.
  • Ensure you update the SSL certificate to support the newly added custom domains if HTTPS is enabled on Heroku.

By setting it up this way, you can achieve the root domain and subdomain pointing to different Heroku applications. This is useful for managing large projects and distributed service architectures.

2024年8月16日 00:23 回复

你的答案