How to configure nginx to redirect to https only for the main domain?

Faced with a strange problem. At a very typical scenario, a redirect from http to https (with www and without www) this config somehow affects the other subdomains. For example, the subdomain sub.site.ru also begins to redirect to https, which was not the case.

server {
 server_name site.ru www.site.ru;
 listen *:80;
 listen [::]:80;

 return 301 https://site.ru$request_uri;
}

server {
 # SSL configuration
 listen 443 ssl;
 listen [::]:443 ssl;
 server_name site.ru;
...
July 2nd 19 at 13:55
1 answer
July 2nd 19 at 13:57
It was includeSubdomains. I had to remove it from:

add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";

Find more questions by tags Nginx