Nginx rewrite rule

November 1 2010

A snippet of my nginx config file showing how to rewrite all urls from www.yourdomain.com to yourdomain.com.

Very simple, but worth knowing if opting for nginx over Apache.

server {
  listen 80;
  server_name www.damiannicholson.com;
  rewrite ^(.*) http://damiannicholson.com$1 permanent;
}


server {
  listen 80;
  server_name damiannicholson.com;
  ...
}