Nginx wildcard subdomain redirect to non-www Nginx wildcard subdomain redirect to non-www nginx nginx

Nginx wildcard subdomain redirect to non-www


To drop the leading www. sequence from the requested server name, place this if block near the top of your SSL server container (before any other URI processing directives):

if ($http_host ~* ^www\.(.*)$ ) {     return 301 $scheme://$1$request_uri;}

Generally if should be used very carefully, but it is perfectly fine in this case.