How to use nginx to make http jump to https? in secondary subdomain name

main domain baidu.com
subdomain b.baidu.com
you can Http to Https
such as http://baidu.com-> https://baidu.com
http://b.baidu.com-> https://b.baidu.com

how do I configure it?
existing configuration:

server {
        listen 80;
        server_name baidu.com;
        rewrite ^(.*)$ https://$server_name$1 permanent;

}
server {
        listen 80;
        server_name b.baidu.com;
        rewrite ^(.*)$ https://$server_name$1 permanent;

}

in this way, the configuration subdomain name cannot be redirected

Mar.07,2021

server {
    listen 80;
    server_name baidu.com;
    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    }
}
server {
    listen 80;
    server_name b.baidu.com;
    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b39592-e6d7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b39592-e6d7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?