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:

  1. Added a CNAME record, with the following info:
    a)Hostname : admin
    b)Aliases to : www.example.com
    c)TTL : 5 minutes

  2. 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>

  3. I enabled the conf (just like i did for the domain)

  4. All permission for the domain (which works) are the same for the subdomain (in terms of directory and files)

  5. 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.

2 Replies

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 www.example.org to example.org will resolve this confusion, creating records for the expected domains admin.example.org and www.example.org.

Domain hierarchy

From the perspective of DNS, www.admin.example.org is considered a different domain name than admin.example.org. As a result, www.admin.example.org and 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 www.example.org and 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.

Personal recommendations

These settings and their interactions can become quite complicated, so I strongly encourage keeping this setup as simple as possible.

  1. Declare your domain name's SOA record to use example.org instead of www.example.org. This will result in hostnames being based directly off of example.org instead of www.example.org, for predictable and easy-to-follow hostname configurations.
  2. Using example.org as your SOA record, create an A record for the www hostname so that www.example.org resolves to the IP address of your Linode, then create a CNAME record for admin mapping 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 www hostname to allow both hostnames to resolve to your Linode's new IP address.
  3. 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 admin.example.org and www.example.org to return the same IP address in a DNS lookup. This ServerName directive 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 admin.example.org.

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.

Thank you very much, this helped very much and I resolved my issue. Cheeerz.

P.S.
Point #5 in my original post, did not happen.

P.P.S
You rock

Thanks

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct