why the root domain did not using https
Solution 1:
Basically it is your cert, not nginx. Can't say anything about it, because you didn't mention anything about it. It is possible to have one cert for both. If you can't change the cert:
Issue 2 certs and go like:
server {
listen 443 ssl;
server_name example.top;
ssl_certificate /etc/nginx/conf.d/cert/example.top/fullchain.pem;
ssl_certificate_key /etc/nginx/conf.d/cert/example.top/private.pem;
return 301 https://www.example.top$request_uri;
}
server{
listen 443 ssl;
ssl_certificate /etc/nginx/conf.d/cert/www.example.top/fullchain.pem;
ssl_certificate_key /etc/nginx/conf.d/cert/www.example.top/privkey.pem;
server_name www.example.top;
...
Or try to redirect before ssl kicks in (never tried):
server {
listen 443 ssl;
server_name example.top www.example.top ;
if ($host = 'example.top') {
return 301 https://www.example.top$request_uri;
}
ssl_certificate /etc/nginx/conf.d/cert/example.top/fullchain.pem;
ssl_certificate_key /etc/nginx/conf.d/cert/example.top/private.pem;
}