Nginx Canonical Domain

Valic —  July 19, 2011 — Leave a comment
############# www to non-www
server{
  listen 80;
  server_name  www.debian-tutorials.com;
  rewrite ^(.*) http://debian-tutorials.com$1 permanent;
}

############# non-www to www
server {
  if ($host ~* ^([a-z0-9\-]+\.(com|net|org))$) {
    set $host_with_www www.$1;
    rewrite ^(.*)$ http://$host_with_www$1 permanent;
  }
}

Enjoy
Page 1 of 11