Help configuring subdomain, one droplet multiple domains

February 3, 2017 601 views
Networking

Im trying to configure a subdomain on one of my domains.
I have one droplet, whit three domains on it.

domain1.com
domain2.com
domain3.com

i want to have a subdomain on one of them
sub.domain3.com

here are my current records for each domain.

domain1.com
A domain1.com directs to 11.11.11.11
CNAME www.domain1.com is an alias of domain1.com.

domain2.com
A domain2.com directs to 11.11.11.11
CNAME www.domain2.com is an alias of domain2.com.
CNAME *.domain2.com is an alias of domain2.com.

domain3.com (This is the one i want to have a subdomain on)
A sub.domain3.com directs to 11.11.11.11

A domain3.com directs to 11.11.11.11

CNAME *.domain3.com is an alias of domain3.com.
CNAME www.domain3.com is an alias of domain3.com.
CNAME *.sub.domain3.com is an alias of sub.domain3.com.

when browsing to sub.domain3.com it will acctually direct me to domian1.com

Why is that? Can someone please help me what im doing wrong?

1 Answer

@joelstahre

How you'd go about setting this up really depends on what web server you're using.

For example, with NGINX, you may setup three server blocks for your domains and then one more for the sub-domains. I've provided a basic overview below.

domain1.com

Since you're not using a WildCard on this domain, the setup would be very simple.

server {
    listen 80;
    server_name domain1.com www.domain1.com;

    ...
    ...
}

domain2.com

Since you're using a WildCard on this domain, we need to activate that in the server block.

server {
    listen 80;
    server_name domain2.com *.domain2.com;

    ...
    ...
}

domain3.com

Much like the second domain, we have a WildCard, so we need to activate it in the server block.

server {
    listen 80;
    server_name domain3.com *.domain3.com;

    ...
    ...
}

sub.domain3.com

Sub-Domains can be treated just like your main domains, and we'd set them up the same. For each sub-domain, we create an entry and we can set them up with our without a WildCard. Since you've indicated that the sub-domain needs a WildCard, we'd activate it as we did with the domains.

server {
    listen 80;
    server_name sub.domain3.com *.sub.domain3.com;

    ...
    ...
}
Have another answer? Share your knowledge.