This is my favorite and I think the more simple if you want permanent redirect from NON WWW to WWW insert the following code in the nginx configuration file nginx.conf :
server {listen 80;server_name www.debian-tutorials.com;rewrite ^/(.*)$ http://debian-tutorials.com/$1 permanent;}
Permanent redirect from WWW to NON WWW in nginx, use this code in your nginx.conf :
server {listen 80;server_namedebian-tutorials.com;rewrite ^/(.*)$ http://www.debian-tutorials.com/$1 permanent;}
Enjoy!

December 6th, 2011 on 23:08
Anytime I had that 1 line in either /etc/nginx/sites-available/default or /etc/nginx/nginx.conf …. It tells me my config is invalid. Oh well.
December 6th, 2011 on 23:21
You can use this:
if ($host = ‘debian-tutorials.com’ ) {
rewrite ^/(.*)$ http://www.debian-tutorials.com/$1 permanent;
}