How do I configure a subdomain on my ubuntu?
I have a domain with Godaddy (www.example.org), I have configured the domain and the nameservers to point at Linode. All that works great.
Now, I want to add a subdomain, www.admin.example.org. I did the following:
Added a CNAME record, with the following info:
a)Hostname : admin
b)Aliases to : www.example.com
c)TTL : 5 minutes
I went to my server and create a virtual host configuration for the subdomain, based on name <virtualhost *:80="">:
a)Created a .conf file for the subdomain
i) ServerName : www.admin.example.org
ii)DocumentRoot: Points to the webroot for the subdomain</virtualhost>
I enabled the conf (just like i did for the domain)
All permission for the domain (which works) are the same for the subdomain (in terms of directory and files)
Linode subdomain help page did not help and I had to go to rehab for using it for 5 days.
Please let me know if you need any more info.
There are a number of important details to consider in this deployment regarding both DNS and Apache.
Start Of Authority records
When adding a domain to Linode Manager, it is important to use the most basic form of your domain name. For example, if you own the domain name
example.org, you should add it to your Domain Manager as
example.org instead of
www.example.org. This form is used as the SOA record and serves as the basis for all hostnames configured under this domain.
Configuring this setting incorrectly can lead to unexpected errors. For instance, if you set your SOA record to
www.example.org, then place a record for the hostname
admin under that domain, this will create a record for
admin.www.example.org. Similarly, a record for
www under this SOA record will create the record for the domain name
www.www.example.org. Changing your SOA record from
example.org will resolve this confusion, creating records for the expected domains
From the perspective of DNS,
www.admin.example.org is considered a different domain name than
admin.example.org. As a result,
admin.example.org each receive their own set of DNS records which are distinct and separate from each other. It is additionally possible to define separate zones for
admin.example.org by using two separate SOA records as described in the previous section.
Apache ServerName directive
It is definitely possible to set up two separate websites on the same Linode. Since these sites share the same IP address, the
ServerName directive becomes necessary so that Apache can use the domain names from incoming HTTP requests to ensure that they go to the correct website.
These settings and their interactions can become quite complicated, so I strongly encourage keeping this setup as simple as possible.
- Declare your domain name's SOA record to use
www.example.org. This will result in hostnames being based directly off of
www.example.org, for predictable and easy-to-follow hostname configurations.
example.orgas your SOA record, create an A record for the
wwwhostname so that
www.example.orgresolves to the IP address of your Linode, then create a CNAME record for
adminmapping it to
www.example.org. This setup ensures that, even if your Linode's IP address changes for whatever reason, you will only need to change the A record for the
wwwhostname to allow both hostnames to resolve to your Linode's new IP address.
- Configure the Apache virtual host block for your administration website with the directive
ServerName admin.example.org. With an SOA record
example.org, a CNAME record for the hostname
admin, and an A record for the hostname
www, this will cause
www.example.orgto return the same IP address in a DNS lookup. This
ServerNamedirective allows Apache to use the domain name of the request, not just the IP address, to ensure incoming connections go to the correct website even though both websites are served from the same Linode.
Wrapping it all together
DNS is a powerful tool enabling complex and scalable configurations. However, this power and complexity comes with the possibility of misconfiguring your domain's DNS settings. As a result, you may see unexpected results such as
admin.www.example.org having a record but not the expected
I hope this answer helps contextualize our introduction to DNS as well as our DNS Manager documentation, and that it ultimately enables you to successfully deploy your desired configuration. Should you be unclear about any of the information in this answer, please don't hesitate to follow up to this answer with whatever questions you may have.