Question

DNS configuration 2 domains

Posted January 28, 2015 2.7k views

Hello,

I have one droplet with 2 distinct DNS entries pointing to it.

domain1.ca. 1800 IN A [ip]
domain1.ca. 1800 IN NS ns1.digitalocean.com.
domain1.ca. 1800 IN NS ns2.digitalocean.com.
domain1.ca. 1800 IN NS ns3.digitalocean.com.
www.domain1.ca. 1800 IN CNAME domain1.ca.
*.domain1.ca. 1800 IN A [ip]

domain2.com. IN SOA ns1.digitalocean.com. hostmaster.domain2.com. 1412268938 10800 3600 604800 1800
domain2.com. 1800 IN A [ip]
domain2.com. 1800 IN NS ns1.digitalocean.com.
domain2.com. 1800 IN NS ns2.digitalocean.com.
domain2.com. 1800 IN NS ns3.digitalocean.com.
www.domain2.com. 1800 IN CNAME domain2.com.

my nginx has those 2 configs:

server {
server_name domain2.com www.domain2.com;

}

server {
server_name domain1.ca www.domain1.ca;

}

My problem is that , if i go to whatever.domain1.ca, nginx leads to my domain2 config.

I tried to play with A and CNAME with no solution, any help?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

3 answers

There is not a directive for wildcard subdomains, so you will be answer by first conf in line

server {
server_name domain2.com www.domain2.com;

}

server {
server_name domain1.ca www.domain1.ca;

}

it should be something around this lines:

server {
server_name .domain2.com;

}

server {
server_name .domain1.ca;

}

It worked, thank you!

If you want to support additional subdomains or have your site act as a catch-all for subdomains in that domain you would want to update your server_name parameter to look like this:

server {
server_name domain1.ca www.domain1.ca *.domain1.ca;
...
}

The addition of the *.domain1.ca tells nginx to serve requests for any name that ends with domain1.ca.

Submit an Answer