Reputation: 10551
While I've done this on my VPS, I've never done this for a heroku application, and now I have to do it for a fairly large company so I really want a simple list of bullet-points in how to do this.
I've read these instructions, and I'm still a little bit unclear on what exactly they mean. Again, if I had more time I'd buy some rubbishy domain and test it myself, but I don't have time on my side and need to get this right first time!
Thankfully, no SSL is required at this time.
Here's what I can gather I need to do to point the url www.foobaryfoobs.com
at my application, running at warm-chamber-1882.herokuapp.com
. Please correct me:
1) I add www.foobaryfoobs.com
to the local repository containing the application.
I presume I do this by navigating to the repository on my local machine and running:
$ heroku domains:add www.foobaryfoobs.com
How does this work? Does it update some configuration file somewhere that I need to add to the repository and then push up to heroku?
Are there any caveats or best practices here? What other domains should I add? heroku domains:add *.foobaryfoobs.com
, for example?
Heroku advises we use the above wildcard domain here. Why?
2) Log into the registrar that created www.foobaryfoobs.com
and navigate to its control panel.
3) Update the domain's CNAME record to point at warm-chamber-1882.herokuapp.com
Am I done for the most part? Now do I just wait?
Is there no IP related stuff?
The domain has several dozen emails attached to it. As long as I don't touch the MX record, I should be fine?
What's a root domain? Why should I add it?
Why should I care that:
Some DNS hosts provide a way to get CNAME-like functionality at the zone apex using a custom record type.
4) Update the domain's FORWARD / URL record so that foobaryfoobs.com
points to www.foobaryfoobs.com
1) Is this how it should be set up?:
The app:
warm-chamber-1882.herokuapp.com
Should have the following configurations (saved in some weird config file that I wouldn't mind knowing more about about):
domains:
www.foobaryfoobs.com
*.foobaryfoobs.com
The domain:
www.foobaryfoobs.com
Should have the following records:
CNAME: warm-chamber-1882.herokuapp.com
URL / FORWARD: foobaryfoobs.com target: www.foobaryfoobs.com
MX: *as long as I don't touch them the emails will still work*
2) Am I covered against:
It’s important to make sure your DNS configuration agrees with the custom domains you’ve added to Heroku. In particular, if you have configured your DNS for *.example.com to point to example.herokuapp.com, be sure you also run heroku domains:add *.example.com. Otherwise, a malicious person could add baddomain.example.com to their Heroku app and receive traffic intended for your application.
3) How should I adjust the steps for a site that has an SSL backend section?
Upvotes: 1
Views: 1640
Reputation: 189
You can also do this with an A/AAAA record.. in my opinion the better way.
Check out my answer in this thread
Heroku EU region how to setup custom domain name?
Upvotes: 0
Reputation: 8132
$ heroku domains:add www.foobaryfoobs.com
How does this work? Does it update some configuration file somewhere that I need to add to the repository and then push up to heroku?
I dont know exactly how does it works internally but this command is equivalent of adding ServerName
in apache config file, without this when request comes to www.foobaryfoobs.com
it will be forwarded to heroku because of dns
but heroku fail to determine your app. You will see the below image.
That's why they need your domain so they know which apps belongs to which domains. They also need it for domain precedence purpose. No changes are required in your code as long as you are okay to allow your user to access Heroku subdomain ie warm-chamber-1882.herokuapp.com
. If you dont want user to access heroku subdomain you have to pass 301
http status so it will be redirected to your actual domain i.e www.foobaryfoobs.com
. For this you have add this in your application controller
before_action :forward_to_domain_if_heroku_subdomain
private
def forward_to_domain_if_heroku_subdomain
if request.host == 'warm-chamber-1882.herokuapp.com'
redirect_to "http://www.foobaryfoobs.com" , status: 301
end
end
Are there any caveats or best practices here? What other domains should I add? heroku domains:add *.foobaryfoobs.com, for example?
if you ONLY want to use www.foobaryfoobs.com
as your domain, this command is suffice ie
heroku domains:add www.foobaryfoobs.com
If you want to assign naked domain foobaryfoobs.com
then you ALSO have to run
heroku domains:add foobaryfoobs.com
If you application use subdomains like subdomain.foobaryfoobs.com
then you also have to run
heroku domains:add foobaryfoobs.com
2) Log into the registrar that created www.foobaryfoobs.com and navigate to its control panel.
To be precious, you have to do DNS management tool.
3) Update the domain's CNAME record to point at warm-chamber-1882.herokuapp.com
Yes.
Am I done for the most part? Now do I just wait?
Yes, but there are also other things.
Is there no IP related stuff?
Yes, there is no ip related stuff.
The domain has several dozen emails attached to it. As long as I don't touch the MX record, I should be fine?
Yes.
What's a root domain? Why should I add it?
if you want to accept requests from user at warm-chamber-1882.herokuapp.com
(not www. warm-chamber-1882.herokuapp.com
) then you have to add it.
Why should I care that: Some DNS hosts provide a way to get CNAME-like functionality at the zone apex using a custom record type.
ALIAS
or ANAME
type of records. (DNSimple provides it). You have to care it because from that custom-record-type it is easily to add record. They are like pre defined templates eg ALIAS
is template of A
record. 4) Update the domain's FORWARD / URL record so that foobaryfoobs.com points to www.foobaryfoobs.com
For a nooby, please explain why this is necessary.
It is necessary because www.foobaryfoobs.com
and foobaryfoobs.com
are different in a same way like images.google.com
and news.google
differs. www
is nothing special it is just a subdomain. If you dont do this, user can't use your site from foobaryfoobs.com
but can access www.foobaryfoobs.com
.
1) Is this how it should be set up?
Yes, it is correct. But if you want to allow foobaryfoobs.com
and www.foobaryfoobs.com
, you have to do something like below table. You dont require *.foobaryfoobs.com
record if your app doesn't use any subdomain except www
. It is bad practice actually to add *.foobaryfoobs.com
.
Type | Name | Content
---------------------------------------
ALIAS | foobaryfoobs.com | yoursite.herokuapp.com
CNAME | www.foobaryfoobs.com | yoursite.herokuapp.com
It’s important to make sure your DNS configuration agrees with the custom domains you’ve added to Heroku. In particular, if you have configured your DNS for *.example.com to point to example.herokuapp.com, be sure you also run heroku domains:add *.example.com. Otherwise, a malicious person could add baddomain.example.com to their Heroku app and receive traffic intended for your application.
Yes. Moreover you dont have to worry about this. If the malicious user can set subdomain at your domain then he capable to do much destruction :P. Actually, malicious user can't access your DNS management tool so you're safe.
Upvotes: 5
Reputation: 4536
In your registrars host records you want to set the @
to the redirect to the www.foobaryfoobs.com and the www
record to the CNAME of warm-chamber-1882.herokuapp.com
, this is because Heroku may change the IP address associated with that hostname and if you have the ip in your registrar you would also have to update. Using a CNAME ties that url to the ip so when Heroku updates the ip your site is still up. As long as you don't touch your MX records your email will be fine.
To protect again *.foobaryfoobs.com
issues they warn about you can also setup a host record for exactly that and make it a CNAME as well pointing at warm-chamber-1882.herokuapp.com
.
As far as setting up the SSL you can look at this article, that should get you setup.
Upvotes: 3
Reputation: 27747
I can answer only some of this:
1) a) It updates some config stored on heroku's end related to your app. You can see that if you login to the heroku site and look at the config for your app. b) dunno c) this will let people type both "http://www.foobaryfoobs.com" and "http://foobaryfoobs.com" and for both of them to go to your app.
Upvotes: 0