https://rtcamp.com/tutorials/nginx/www-non-www-redirection/
Nginx config for www to non-www and non-www to www redirection