A domain is good for much more than one website. You can have app.midominio.com on one machine, intranet.midominio.com on another and clientes.midominio.com on an external service, without buying anything else: they are subdomains, and in Route 53 each one is a single line. And then there is the eternal question of www: making both ways of writing your domain lead to the same website. This guide solves both and clears up a common misunderstanding: DNS says where each name goes, but it does not redirect; the server does that.
Before you start: what each thing means
- Domain and subdomain
- midominio.com is the domain; anything in front of it separated by a dot (app.midominio.com) is a subdomain. They are created in DNS, not bought.
- Route 53 and hosted zone
- Amazon's DNS and your domain's "file" inside it, with all its records.
- A record
- A name points to an IP address. This is what you use for a machine of your own.
- CNAME record
- A name points to another name. Used for external services ("clientes.midominio.com goes to whatever.provider.com"). It cannot be placed at the root of the domain.
- Alias record
- A Route 53 invention that works like a CNAME but also at the root, for pointing to AWS services (CloudFront, load balancers, buckets).
- Wildcard (*)
- A *.midominio.com record answers for any subdomain that does not have its own record.
- Redirect
- When opening one address the browser ends up at another. It is done by the web server (or a service), not by DNS.
- TTL
- Seconds that others may remember the answer. Low while you are changing things, high once it is stable.
Step by step
Open your domain's zone
Route 53 console, Hosted zones, click your domain. You will see the records it already has: the root A record, perhaps the www one, the MX records for email. Each new subdomain will be one more record in this list.
Create a subdomain pointing to a machine of yours
Create record. Name: just the front part (
app; Route 53 adds the domain). Type A. Value: the machine's static IP. TTL 300. Create. Within a few minutesapp.midominio.comreaches that machine; the machine's web server has to know how to answer for that name (a "virtual host" or "server block"), otherwise it will show the default website.Create a subdomain pointing to an external service
Your helpdesk, shop or newsletter provider tells you something like "create a CNAME from
clientestomidominio.proveedor.com". So do exactly that: Create record, nameclientes, type CNAME, value the name they gave you (without http:// and without a trailing slash). If the provider is an AWS service (CloudFront, a load balancer), use type A with the Alias toggle on and pick it from the dropdown.Decide what to do with www
First, both names must reach your server: the root with an A record to the IP, and
wwwwith another A record to the same IP (or a CNAME tomidominio.com). That is as far as DNS goes. Second, choose which one is the "official" name (nowadays usually without www) and have the other one redirect to it, so that Google does not see two identical websites and the padlock works on both.Do the redirect on the server
This is not done in Route 53. On the machine, the web server has to answer
www.midominio.comwith a permanent redirect (code 301) tomidominio.com. In Apache, in the site's block:RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.midominio\.com$ [NC] RewriteRule ^(.*)$ https://midominio.com/$1 [R=301,L]In Nginx it is a
serverblock for www with areturn 301. If you use the Bitnami blueprints on Lightsail, thebncert-toolasks exactly this when setting up the certificate and configures it for you. The HTTPS certificate must cover both names.Check and raise the TTL
Open all four combinations (with and without www, with http and https): all of them must end up at
https://midominio.comwith the padlock. Open the new subdomain. Once everything has been stable for a few days, raise the TTL of the records to 3600 or more: fewer queries and faster answers.
What can go wrong
Route 53 will not let me create a CNAME at the root
It is a DNS rule. At the root use an A record with the IP, or an alias if the target is an AWS service. If the target is an external service that only gives you a name, ask them whether they have a fixed IP or put CloudFront in front.
The subdomain resolves but shows a different website
DNS has done its part; the server does not know that name is its own and shows the default site. Add the name to the virtual host (Apache) or server block (Nginx) of the right site.
I want a subdomain for each customer without creating records one by one
Create a wildcard record: name *, type A, the machine's IP. Any loquesea.midominio.com will reach it, and your application decides what to show based on the name. Specific records you create separately take priority over the wildcard.
I changed a record and nothing happens
TTL. Intermediate servers remember the old answer until it expires. Lower the TTL a few days before a planned change; if it is already done, all you can do is wait.
In Simplio
In Simplio each Route 53 domain is a card where the records read in plain language and creating a subdomain means choosing the name and the destination machine from a list: Simplio fills in the IP. Records for external services are added in one line with help according to the type, replacing an existing one asks for confirmation and removing one asks for two-factor. And the activity log keeps who changed what.
The same task, in AWS and in Simplio
| In the AWS console | In Simplio | |
|---|---|---|
| Creating a subdomain | Route 53, Create record, pick a type out of 12 options, TTL | A line "app → this machine" on the domain card, with the IP already filled in |
| Knowing where each name points | Read the table of technical records | List in plain language: "the website goes to machine X, email is received by Y" |
| Breaking something | Anyone with access can delete a record | Removing a record asks for two-factor; NS and SOA are protected |