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 also begins to redirect to https, which was not the case.

server {
 listen *:80;
 listen [::]:80;

 return 301$request_uri;

server {
 # SSL configuration
 listen 443 ssl;
 listen [::]:443 ssl;
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