Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Accepted Answer
If someone need this, solution is:
if ($host ~* ^www\.(.*)) {
set $host_without_www $1;
rewrite ^(.*) http://$host_without_www$1 permanent;
}
Hello, thanks.
But I think we did not understand each other :)
What I need is redirect from www subdomain to non www subdomain, not to domain.
So:
www.sub.example.com redirect to sub.example.com
www.sub2.example.com redirect to sub2.example.com
and NOT:
www.sub.example.com to example.com
But I dont have conf files for each of this subdomains. I have only one sub nginx conf as I mentioned in my first question.
Thank you.
You can target all www.*.domain.com hostnames by using a regular expression:
server {
listen 80;
server_name ~^www\..+\.domain\.com$;
return 301 $scheme://domain.com$request_uri;
}
Make sure you escape any dots in your domain name by adding a \ before them like in the snippet above.