Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I would setup for this:

  • user go to test.example_site1.org
  • test.example_org1.org it's a CNAME of test.example_org2.org
  • user will see the page of test.example_org2.org

On the example_org2.org server I use nginx and I have 3 django projects.

test.example_org2.org shows the third django project. http://example_org2.org shows the first django project.

The problem is that I've setup a CNAME on the example_org1.org for pointing test.example_org1.org to test.example_org2.org , but if I try to go to http://test.example_org1.org I see the first django project, which one configurated to the main domain and not to subdomain. Otherwise if I go directly to http://test.example_org2.org all it works and I see my correct project.

Why this issue?

share|improve this question
might help if you show some conigs –  Mike Aug 17 '11 at 12:35

2 Answers 2

up vote 2 down vote accepted

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*. 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;
share|improve this answer
"If is Evil" wiki.nginx.org/IfIsEvil –  Alexander Azarov Aug 17 '11 at 16:03
Agreed. He could use plain rewrite, but again, it was an example ;). –  Torian Aug 17 '11 at 16:08
Unfortunately these examples are getting copied all over the Internet –  Alexander Azarov Aug 17 '11 at 16:10
I'd bother on all over their site rather than all over the internet. Anyway, if it bothers him (or you ;)) that much, he could try rewrite ^/(django/path/to/app)(/.*)? test.example_org2.org/$1$2 permanent`, but there is no way to know what hostname is being requested (not that I know of). If someone does, enlighten us. –  Torian Aug 17 '11 at 16:26

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;

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.