Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would setup for this:

  • user go to
  • it's a CNAME of
  • user will see the page of

On the server I use nginx and I have 3 django projects. shows the third django project. shows the first django project.

The problem is that I've setup a CNAME on the for pointing to , but if I try to go to I see the first django project, which one configurated to the main domain and not to subdomain. Otherwise if I go directly to 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
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, which points to IP*. Then, the browser connects to this IP, and sends a Host header with a value of (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 then it should be redirected to (untested):

if ($host ~* "^$"){
  rewrite ^(.*)$ permanent;
share|improve this answer
"If is Evil" – 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)(/.*)?$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 to the server_name along with

server {

share|improve this answer
I had a A record with my own subdomain, but I wanted to mask the actual address with a CNAME, and I would always get the default_server served. This fixed it for me. – Housemd Apr 24 at 10:03

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.