Nginx – How to add subdomain CNAME alias to other domain subdomain without redirection

domain-name-systemnginx

I have two domains, I own both.
domain1.com and domain2.com

on domain2.com I have a subdomain my.domain2.com which has an A DNS pointing to an nginx.

I want other.domain1.com to view content from my.domain2.com without redirection.

What I did is to setup a CNAME from other.domain1.com to my.domain2.com
But when I enter visit it it redirects to my.domain2.com instead of showing me the content.

Is this from DNS settings or nginx should be setup differently?

Best Answer

To serve the same content out of 2 (sub)domains just set multiple server blocks:

server {
  server_name other.domain1.com
  location / {
    root /var/www/wordpress;
  }
}

server {
  server_name my.domain2.com
  location / {
    root /var/www/wordpress;
  }
}

CNAMEs are not required, you can have two domains A record point to the same IP address.

Related Topic