Rewrite subdomains with nginx 0.6.x

Posted by Dan Sosedoff on January 15, 2009

Problem: You have a domain name ‘www.domain.com’ that needs to be redirected to ‘domain.com’.

Solution:

In your nginx config file (i`m keeping all configs for all sites separate in different files), befor ’server’ block configuration you should put this piese of code:

server {
    server_name www.domain.com;
    rewrite ^(.*) http://domain.com$1 permanent;
}
server {
... actual server configuration ...
}