Setup CNAME for subdomain issue

Solution 1:

CNAME are there only to say sub1.domain has the same IP than sub2.domain. But it does not tell a web server that they should serve the same content.

When you enter the domain name on your browser, it checks the IP via a DNS query, and it gets an answer saying this is a CNAME for test.example_org2.org, which points to IP 1.2.3.4. Then, the browser connects to this IP, and sends a Host header with a value of test.example_org1.org (because that is what you requested). Ngnix gets this, and as it doesn't know anything about it (is not in its config) then it serves the first virtualhost it has.

You could tell the default virtualhost that if someone asks for test.example_org1.org then it should be redirected to test.example_org2.org (untested):

if ($host ~* "^test.example_org1.org$"){
  rewrite ^(.*)$ http://test.example_org2.org permanent;
  break;
}

Solution 2:

what about adding test.example_org2.org to the server_name along with test.example_org1.org

server {
   server_name test.example_org1.org test.example_org2.org;

...
}