if ($host ~* www\.(.*)) { set $host_without_www $1; #rewrite ^ $scheme://$host_without_www$request_uri permanent; return 301 https://$host_without_www$request_uri; }