if ($host ~* ^www\.(.*)$) { rewrite / $scheme://$1 permanent; } code example
Example: if ($host ~* ^www\.(.*)$) { rewrite / $scheme://$1 permanent; }
if ($host ~* www\.(.*)) {
set $host_without_www $1;
rewrite ^(.*)$ http://$host_without_www$1 permanent; # $1 contains '/foo', not 'www.mydomain.com/foo'
}