nginx www.domain.com vs domain.com virtualhost

Posted by m33lky on Server Fault See other posts from Server Fault or by m33lky
Published on 2011-11-20T04:52:01Z Indexed on 2011/11/20 9:59 UTC
Read the original article Hit count: 327

I have an http block where I include virtual hosts for the different domains hosted on the same server. For each virtual host I do:

listen domain.com:80;

Now, domain2.com works fine. However, when I do www.domain2.com it shows the page for domain1.com!

How to properly configure nginx? Does this have something to do whether www is a CNAME or an A record?

Update: It looks like you can do the following:

listen 80;
server_name domain.com www.domain.com;

© Server Fault or respective owner

Related posts about nginx

Related posts about virtualhost